A
ArielZusya
I've got the following code:
Sub CreateButton()
Dim btnMyButton As Button
Set btnMyButton = ActiveSheet.Buttons.Add(460, 75, 140, 30)
btnMyButton.Caption = "Delete and Update Charts and Lists"
btnMyButton.Select
Selection.OnAction = "btnDeleteAndUpdateSeatingChart"
Selection.Name = "btnDeleteAndUpdate"
End Sub
If I create a new workboox and then create a module with this sub in it and
then run it it works without error. However, when I run it from a second
workbook I get the error. In other words if I use the current workbook to
run vba script that copys the current worksheet to a new workbook and then
while that new workbook is active I run the above code it creates the button
on the new worksheet but when it tries to change the caption on the button
from "Button 1" to "Delete and Update Charts and Lists" I get Runtime Error
1004: Unable to update the Caption Property of the Button Class. Anyone have
any idea why this would be? I've tried saving the new workbook before
running the create button script and it had no impact on the problem. This
is in Excel 2007. Your help is greatly appreciated. Thanks!
Sub CreateButton()
Dim btnMyButton As Button
Set btnMyButton = ActiveSheet.Buttons.Add(460, 75, 140, 30)
btnMyButton.Caption = "Delete and Update Charts and Lists"
btnMyButton.Select
Selection.OnAction = "btnDeleteAndUpdateSeatingChart"
Selection.Name = "btnDeleteAndUpdate"
End Sub
If I create a new workboox and then create a module with this sub in it and
then run it it works without error. However, when I run it from a second
workbook I get the error. In other words if I use the current workbook to
run vba script that copys the current worksheet to a new workbook and then
while that new workbook is active I run the above code it creates the button
on the new worksheet but when it tries to change the caption on the button
from "Button 1" to "Delete and Update Charts and Lists" I get Runtime Error
1004: Unable to update the Caption Property of the Button Class. Anyone have
any idea why this would be? I've tried saving the new workbook before
running the create button script and it had no impact on the problem. This
is in Excel 2007. Your help is greatly appreciated. Thanks!