Reputation: 61
I'm writing an Excel VBA code that transfers data to a Word document. I'm using the command Application.Selection.Find
and Application.Selection.InsertAfter
in order to fill in the blanks in the Word document.
The problem is that after I select one item I can't select another one.
I would like to be able to unselect an item so that I could freely select another using the same command. How?
Upvotes: 6
Views: 13272
Reputation: 111
You have more than one option depending on where you want the cursor after the operation. Option 1 is probably the most common presuming you are done working on the current selection and want to move forward, but in some cases you may want to do something just before that selection, but be careful to not enter into an infinite loop.
This unselects the selection and puts the cursor after the current selection.
Selection.EndOf
This unselects the selection and puts the cursor before the current selection. Note: with the cursor placement before the current selection it is possible to enter an infinite loop.
Selection.Collapse
Microsoft says that this is an option, but I am working in Word 2013 and it is not an option for me. Maybe it works in something more recent than 2013? Ref https://learn.microsoft.com/en-us/office/vba/api/publisher.selection.unselect
ActiveDocument.Selection.Unselect
Upvotes: 2
Reputation: 115
Alternatively can use this. This will send the cursor to the end of the Word document.
Selection.EndKey Unit:=wdStory
[SOURCE: https://software-solutions-online.com/word-vba-move-cursor-to-end-of-document/]
Upvotes: 1