我正在尝试在共享工作簿中创建/复制/复制excel VBA中的任何内容。我的目标是在共享工作簿时创建新按钮。
在标准工作表模式中,我尝试过在标准模式下工作,但在共享模式下失败(VBA不知道.add按钮方法)
Sub copyButton3()
Dim projectSheet As Worksheet
Set projectSheet = Sheets("Projects")
Dim newButton As button
With projectSheet
Set newButton = .Buttons("buttonToCopy").Add(10, 10, 10, 10)
With newButton
'some changes like name, size, caption, on action...
End With
End Sub
然后我尝试了Duplicate方法,但结果与Add
相似Sub copyButton3()
Dim projectSheet As Worksheet
Set projectSheet = Sheets("Projects")
Dim newButton As button
With projectSheet
Set newButton = .Buttons("buttonToCopy").Duplicate
With newButton
'some changes like name, size, caption, on action...
End With
End With
End Sub
然后我尝试使用复制和粘贴,在这里我取得了一些成功。最后,创建了新按钮,但我无法操纵他,因为我无法选择他。我尝试将选择分配给按钮变量,但在共享模式下我得到Run time error 438 Object doesn't support this property or method
(在正常模式下,一切都像魅力一样)。
Sub copyButton()
Dim projectSheet As Worksheet
Set projectSheet = Sheets("Projects")
Dim newButton As Variant
With projectSheet
.Buttons("buttonToCopy").Copy
.Paste
Set newButton = Selection
With newButton
.Caption = "selected Button"
End With
End With
End Sub
所以现在我几乎没有想法。
甚至可以欺骗VBA在共享模式下创建新按钮(我可以创建它)但是稍后再操作它?