Why can't I select when I'm setting up a macro

R

REVA

I am trying to set up a macro that will Select Cells in a Table and then
Paste from the Clipboard. I am not very good with Macros and am using the
Record feature to do the macro. When I turn it on, it will NOT let me Click
in the cell where I want to start my paste. Can anyone help? This is soo
easy manually, and since I have to Paste the same info in several different
places, I want to be able to Macro it. I am copying selected cells (across)
from Excel and pasting them (down) into a several Word tables within the same
document.
 
K

Kevin B

You can use the keyboard to select cells/rows in a table by holding down the
shift key, but the mouse click & drag method does not get recorded.

You can also programmatically select cells in a table with something like


ActiveDocument.Tables(2).Cell(2, 1).Select

Which would select the second row, first cell in the second table of the
active document.

Hope this helps...
 
A

AnneT

Reva and Kevin,

I am trying to do something very similar in Word. I use macros in Excel,
and was very surprised to learn that you lose cursor selection with recording
macros in Word. Kevin, thanks for you post - i have several fields which i
need to update in tables, and by using your code, i was able to set up my
macro successfully.

Two questions as follow up
1. I have my tables bookmarked to specify names for them. Is their a way
to specify the bookmarked name, rather than just "Tables(#)". For example,
one table is bookmarked as "TotalTable". How would I code that? I tried
both Tables("TotalTable") and Tables(TotalTable) - no luck. If I can't use
the bookmarked name, is there a way to view the Word name/number for the
table -without counting the number of tables in the document and missing some.
2. In Excel I have created applications with macros assigned to buttons,
which are graphically embedded in the worksheet. The user just selects the
button in the worksheet to run the macro - much easier and intuitive than
assigning the macro to a toolbar. Does Word have the same capability? I've
used the help menus, but didn't see that option. I'm hoping....

Thanks in advance
 
K

Kevin B

You can select the bookmark with the first line of code, and then type
whatever text you want with the second line of code

ActiveDocument.Bookmarks("Book Mark Name as a string").Select
Selection.TypeText Text:="What you want to type."

FYI: If you're going to be doing any real coding in Word I highly recommend
the "Word 2000 Developer's Handbook" by Guy Hart-Davis, published by Sybex.

This book is now out of print but I was able to get a copy of it from
Amazon. It's a little pricey as books go, but it is most definitely worth it.

Happy coding...
 
K

Kevin B

I'm so A-D-D that I just zipped by question number 2.

You can place buttons in a Word document using ActiveX controls. To access
these tools right click on any Word tool bar and select Control Toolbox
toolbar.

By default these buttons will print, and although you might be able to
supress the printing of these object, I don't know off the top of my head
what you would need to do to set this. In Excel, when you right click on a
button one of the properties is PrintObject, a True/False property, but I did
not see this property associated with the button in Word.

I
 
A

AnneT

Kevin,

Thanks - I didn't think of "Bookmarks" as the object - I was trying "Tables"
and "Fields"! I'm almost there - I have both an activex command button and
an image control in my document, both with the correct code to update the
fields. Nothing seems to happen when I select the buttons - it doesn't
matter if the form is protected or not. My macro works fine - on a toolbar,
and working. The same code attached to an activex control does not. I know
I'm missing something basic here. I'm just using the "Word 2003 Inside and
Out" book - I'll look into the programming guide - but in the meantime, I
appreciate your help. Any ideas of why the activex controls don't work?
They don't generate any errors either - I just click and nothing happens.
 
K

Kevin B

When you inserted your command button you were placed in design mode, did you
turn design mode off before attempting to run the macro.

The design mode toggle is on the the Control Toolbox, it's the button with
the triangle, pencil and ruler.
 
A

AnneT

Yes, I went out of design mode - and I tried the buttons with both form
protection on and off - no difference. My macro on the toolbar runs with
either protection on or off. I don't know why the code in the ActiveX
buttons won't work. No error, nothing. When I click the buttons, nothing
happens. The code is the same as the macro- I just copied it over. Do I
need to enable something in tools or in my document for ActiveX controls? It
looks like the document is not recognizing that the code is there. If I
purposely make an error in the code - I don't even get a runtime error.
Thanks for your help - I really appreciate your time.
 
K

Kevin B

Mmmmm.

Assuming that you have the button code assigned to the OnClick event, have
you tried just referencing your macro, which you know works, instead of
putting the macro code in the OnClick event?

Why don't you remove all the macro code for the OnClick event and replace it
with the name of your macro instead and see if that works.
 
A

AnneT

Got it!!

I had to change my macro security level to run the code in the ActiveX
controls. I don't really understand why the macro ran as a macro in the
"normal.dot" template and not as code in the specific document, but it
didn't. I knew something was different because it didn't even give me error
messages.

Thanks so much for all your help and persistance!

Happy New Year - Anne
 
K

Kevin B

Glad to hear you finally got it working, and wouldn't you know it would be
something that obvious. Never fails...
 

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