View Single Post
 
Old 11-16-2017, 02:36 AM
slaycock slaycock is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default

You need to be careful with the word 'forward' and 'backward'. With Moveuntil 'Forward' means towards the end of the document, 'Backwards' vice versa.

Hence if you place the cursor at the end of the text and search forwards it will move 0 characters because it cannot go any further 'Forward'.

The other point to consider is if you were using 'Option explicit' or not. If you weren't then wdForeward would be created as a new word variable of type variant and assigned the value 0 rather than being treated as typographical error (. Hence your use of wdForeward is a request to move forward 0 characters which is exactly the action you got.

Additionally, if you'd checked the token wdForeward in the object browser you would have found it didn't exist.

Lesson learned

1. Always always always use option explicit
2. Read the VBA word object model help pages very very carefully.
Reply With Quote