Thread: [Solved] How to cancel a selection?
View Single Post
 
Old 01-12-2019, 08:53 PM
johngross johngross is offline Windows XP Office 97-2003
Novice
 
Join Date: Jan 2019
Posts: 3
johngross is on a distinguished road
Question How to cancel a selection?

I have been trying to convert some documents, that were originally written under an old word-processing package, into MSWord documents, and I've come across a problem that I don't seem to be able to solve.

The old WP software used certain non-text characters to enclose text that was to appear in bold face on the printer, so I have been working on a VBA macro to turn those bits of text to bold as MSWord understands it. I have successfully written the code to find the symbol for bold, then delete it, then select the text up to and including the next "bold" symbol and make it "MSword" bold, and finally to delete the second "bold" symbol.

Everything looks fine up to this point, but I would like the macro to loop through this code to do the same to all the words that were flagged as bold, so I enclosed my code in a "Do ... Loop" with a line - immediately after the .Find method code for the "start bold" symbol - to exit the sub if that symbol hasn't been found.

This should work fine, shouldn't it? Only it won't! It exits the sub after the first iteration, and the only explanation I can think of is that the sub seems to think it still has a "selection" active, so that the second time through the .Find code it searches only the "selection" and of course that doesn't contain the symbol. This is supported by putting a MsgBox(Selection) command at the critical point that produces either a single space or a comma/colon/semi-colon - in other words, it suggests that VBA still thinks there is a selection "there".

I have tried everything I can think of to "cancel" or "deselect" or "unselect" this selection - in particular, the .Collapse method - but nothing seems to work.

Can anyone suggest what I think I must have missed... or will I be forced to assign my macro to an Fn key and just keep tapping it until it reaches the end of the document?
Reply With Quote