Deleting a command button...

  • Thread starter Thread starter John Keith
  • Start date Start date
J

John Keith

THIS MONTH has a command button named "btnProcessData"
After the copy, the new sheet that has been renamed to the text string
stored in sWksName still has the button named exactly the same (verified with
a For Each loop displaying the names of all shapes on the new sheet)
Why does this code cause an error?

With ThisWorkbook
.Sheets("THIS MONTH").Copy After:=.Sheets(.Sheets.Count)
.Sheets("THIS MONTH (2)").Name = sWksName
.Sheets(sWksName).Shapes("btnProcessData").Delete
End With

The ".delete" is getting a runtime error 1004 application defined or object
defined error.
 
It is named the same. A for each sh in activesheet.shapes... showing all
shape names in a msgbox verified that the name was the same.

I discovered the problem was that my sheet was protected. There really
should be a better error message to report when you are trying to change a
protected sheet. Maybe since this is a shape as opposed to a value or
formula MS didnt extend the errors to fully cover shapes.
 
Some of the error messages are lacking in specificity and you have to do a
lot of trouble shooting to tie down the problem. I was not sure about the
name transfer. I know it copies any associated code over for each control,
guess I should have assumed the name would be copied over also. Glad you
found the problem and thanks for posting back. Helps me learn also.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top