请教在当前单元格创建按钮的问题 - Windows专区 / Microsoft Office应用

状态: 已解决 - 阅读:115 - 提问时间: 2011-08-15 13:44:05 - 引源:CSDN论坛 - 校对:[女]
关键字:,Windows专区
'创建按钮
Dim BtnName As String
Dim Btn As CommandButton
Dim BtnSendPay As OLEObject
Set BtnSendPay = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False, _
  DisplayAsIcon:=False, Left:=10, Top:=10, Width:=100, Height:=20).Select


请问我用上面的方法创建按钮后,按钮位置怎么总是在左上角的单元格,而不是当前选定的单元格呢?
smarteyeexit Replied at : 2011-08-15 13:47:00
对了,我一加Select后,还提示我错误 
"运行时错误:424" 要求对象
smarteyeexit Replied at : 2011-08-15 14:11:24
顶一下
laoyebin Replied at : 2011-08-15 16:19:21
Left:=10, Top:=10, Width:=100, Height:=20 这个改一下
smarteyeexit Replied at : 2011-08-15 17:05:49
引用 3 楼 laoyebin 的回复:
Left:=10, Top:=10, Width:=100, Height:=20 这个改一下


我把left 和 top 取消后,也不行.
另外一加Select ActiveSheet.OLEObjects.Add(...).Select
就提示我错误  
"运行时错误:424" 要求对象

请问什么问题呢? 缺少什么引用吗
smarteyeexit Replied at : 2011-08-15 18:17:03
解决了,是改了一下Left:=10, Top:=10, Width:=100, Height:=20 

把解决办法放出来


   
  '当前位置
  Dim bLoc As Range
  Dim bTop As Single
  Dim bLeft As Single
  Dim bHeight As Single
  Dim bWidth As Single
  Set bLoc = Range(ActiveCell, ActiveCell)
  bTop = bLoc.Top
  bLeft = bLoc.Left
  bHeight = bLoc.Height
  bWidth = bLoc.Width

ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False, _
  DisplayAsIcon:=False, Left:=bLeft, Top:=bTop, Width:=bWidth, Height:=bHeight)
 
相关问题
 

 
- 最新问答
最新问题
最近完成的问题
热点标签云
 
业界新闻资讯