tags:

views:

44

answers:

1

I have a macro, that change selected text, assigned to button. It works perfectly when i run macro from visual basic, but when I click button it gets focus and my text is no longer selected so macro change selected element (button). How can I select text and run macro by click on button?

+2  A: 

Is the button embedded in the document? You may need to put it on a form that loads on top of the Word window or in a menu/toolbar, so that clicking it does not affect the selection in the document itself.

Edit:
I think you can use Application.Selection.Previous to get at what you need. You could use this to restore the selection after the click event, or to act upon that section of the document, or both.

I assume that this is available in previous versions of Word, but have only confirmed its presence in 2007.

Jay
Yes, the button is embedded into document. When i add button to top menu it works, but i have to use embedded button ( lecturer's request )
Ethylparaben