Solved

VBA to delete command button in MS-Word

Posted on 2013-11-12
5
1,602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 51

Accepted Solution

by:
Rgonzo1971 earned 500 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 51

Expert Comment

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

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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