Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1815
  • Last Modified:

VBA to delete command button in MS-Word

I recently had some help by expert GrahamSkan to come up with the code below.   It works great but I need some assistance with a minor change.

*************
Sub CopyMe()
        Dim doc As Document
        Set doc = ActiveDocument
        doc.Shapes(1).Delete
        doc.SaveAs "C:\MyFolder\Test.doc"
End Sub
*************

The above code "deletes" a shape (i.e., rectangle) which calls the macro.

Now, instead of using a rectangular shape, I prefer to use a command button.

My question:   In MS-Word, what line(s) of code replaces the line "doc.Shapes(1).Delete" to remove "CommandButton1" instead?

EEH
0
ExpExchHelp
Asked:
ExpExchHelp
  • 3
  • 2
1 Solution
 
Rgonzo1971Commented:
Hi,

Maybe

doc.InlineShapes(1).Delete

Open in new window

Regards
0
 
ExpExchHelpAuthor Commented:
Rgonzo1971:

Thanks for the prompt response.

I've replaced the shaped with a command button.

When clicking on the command button, however, nothing happens... except that the VBA editor is opened and the cursor flashed before line "Dim doc As Document".

Nothing is highlighted indicating a compile/syntax error though.

What's missing?

EEH
0
 
Rgonzo1971Commented:
Have you tried to close and reopen the file?
0
 
Rgonzo1971Commented:
Is the macro linked to the button?
0
 
ExpExchHelpAuthor Commented:
"That was easy!".    Yes, that's what it was... I had to close/reopen the document.

Thanks,
EEH
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now