简体   繁体   中英

MS-Word-VBA UserForm - How to run a macro from a command button to a specific location inside the document?

I can't figure out how to run a macro at a specific spot inside the Word document when a user presses the command button on the UserForm. Currently when the command button is pressed the macro runs at the beginning of the document. I tried finding a bookmark and running the macro there, but it still only initiates at the beginning of the document or wherever the last place the mouse clicked on the Word document. Inside the document I have field codes around a checkbox, so when the checkbox is clicked "Yes" the macro runs and lines out a few sentences.

Original Checkbox in pic

在此处输入图片说明

This is what it is suppose to look like when the macro runs

在此处输入图片说明

Now the Macro works fine when the user clicks the checkbox on the document. The code works inside the userform when the command button is clicked, but it runs the macro at the beginning of the document or wherever the mouse clicked last, instead of at the location of the checkmark. Basically what I can't figure out is how to have the code click near the checkbox and then run the macro. Any help would be greatly appreciated, thanks.

I was able to finally figure this out. I delayed asking the question on here for days trying to do research on my own. But of course, hours after I post on here I figure it out.

All I needed was these 2 lines

ActiveDocument.Bookmarks("BookmarkName").Select
MacroName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM