Command Button

A

Anne

I am new to Macros and need to have a macro assigned to a button that will
run an OPEN FROM FILE event. i have a word document that i would like to
place a button into where if clicked, it will open a folder in which pictures
are placed. I can then select the picture and place it into the document.
Also, this picture has to be placed in a specific position within the
document, ie. Top Right corner
 
J

Jonathan West

Anne said:
I am new to Macros and need to have a macro assigned to a button that will
run an OPEN FROM FILE event. i have a word document that i would like to
place a button into where if clicked, it will open a folder in which
pictures
are placed. I can then select the picture and place it into the document.
Also, this picture has to be placed in a specific position within the
document, ie. Top Right corner

First stage is to work out how to open a dialog to allow you to select a
picture. for this, look up the FileDialog object in Word VBA. There are code
examples there describing how to use it. (FileDialog is only available if
you are using Word 2002 or later. If you have Word 97 or Word 2000, let me
know and I'll suggest an alternative approach.)

The next stage is to take the filename and insert the picture into the
document. Take a look at the AddPicture method of the Shapes collection

The next stage is to format the Shape object so that it is in the top right
hand corner. For this, you need to do several things to the Shape object

- Set its RelativeVerticalPosition property to
wdRelativeVerticalPositionPage
- Set its RelativeHorizontalPosition Property to
wdRelativeHorizontalPositionPage
- Set its Top and Left properties to zero.

Once you have created the macro, you then need to assign it to a button. If
you mean a toolbar button, take a look at this article

How to assign a Word command or macro to a toolbar or menu
http://www.word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToToolbar.htm

If you want to click on something in the document itself to run the macro,
take a look here

Run a macro when a user double-clicks a button in the document
http://www.word.mvps.org/FAQs/MacrosVBA/AssignMacroToButton.htm

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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

Top