Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBA to delete command button in MS-Word

Posted on 2013-11-12
5
Medium Priority
?
1,769 Views
Last Modified: 2013-11-12
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
Comment
Question by:ExpExchHelp
  • 3
  • 2
5 Comments
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39641526
Hi,

Maybe

doc.InlineShapes(1).Delete

Open in new window

Regards
0
 

Author Comment

by:ExpExchHelp
ID: 39641546
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
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39641559
Have you tried to close and reopen the file?
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39641560
Is the macro linked to the button?
0
 

Author Comment

by:ExpExchHelp
ID: 39641563
"That was easy!".    Yes, that's what it was... I had to close/reopen the document.

Thanks,
EEH
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question