Solved

VBA to delete command button in MS-Word

Posted on 2013-11-12
5
1,474 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 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
Hi,

Maybe

doc.InlineShapes(1).Delete

Open in new window

Regards
0
 

Author Comment

by:ExpExchHelp
Comment Utility
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 48

Expert Comment

by:Rgonzo1971
Comment Utility
Have you tried to close and reopen the file?
0
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Is the macro linked to the button?
0
 

Author Comment

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

Thanks,
EEH
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now