Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a Macro in word2007, it is not working

Status
Not open for further replies.

lupidol

Programmer
Apr 23, 2008
125
IL
Hi everyone,
Since i often add keywords to an Index-list i thought i might create a macro to commit
that process automatically.
I select a keyword ("abcd" for example) then i click on the "Macros" button,
give a name to the new macro and then i click "Button", select the new macro from list,
click "Add" to insert it to the "Quick access toolbar and" and after the OK i select "Reference"
from the ribbon, Add index etc.. At the end i select "Stop recording Macro" and a new keyword - "abcd"
is added to my index.
Next, i select a new keyword: "efgh", click the above macro button but guess what: an old "abcd"
keyword is added to my index. I cannot add any other word but "abcd".
Can i get some help please ?
 
What is the code behind your macro that you are currently using? My guess is that you are using a static value "abcd" instead of a variable for the value. If you use a variable, you can have the variable change however you want...

So..

abcd1
abcd2
abcd3
abcd4
abcd5
etc..

or

Using an Input box, you could prompt for the new name.

--

"If to err is human, then I must be some kind of human!" -Me
 
Change the macro code to use Selection.Text - rather than your hard coded "abcd". The macro will use whatever is the selected text.

faq219-2884

Gerry
My paintings and sculpture
 
Yes, the "selection.text" should work best, as fumei pointed out. The variable could be use to represent that data, but wouldn't be necessary.

--

"If to err is human, then I must be some kind of human!" -Me
 
Thanks a lot.
How do i get that "Selection Box" ("Input Box")?
I'll try VBA forum.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top