Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

LinkBack Thread Tools Display Modes
Old 01-12-2019, 08:53 PM
johngross johngross is offline Windows XP Office 97-2003
Join Date: Jan 2019
Posts: 1
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
Old 01-12-2019, 10:15 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,467
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold

The problem is that your code selects something. There is rarely any need for content to be selected via code, or otherwise unless you want to restrict processing to a selected range. See, for example, the second macro in: That said, without seeing your code and a document with a representative sample of the content you're trying to process, we're limited in the advice we can give.
Paul Edstein
[MS MVP - Word]
Reply With Quote

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Cancel ComboBox Dropdown skarden Word VBA 0 09-29-2013 09:21 PM
How to cancel printing?? RDA1959 Word 1 08-28-2011 12:44 AM
Can't cancel Reveal Formatting dave7777 Word 2 05-15-2011 01:18 PM
How do I cancel reminders permanently? fmt Outlook 0 12-15-2010 12:02 AM
Red X on Cancel All and Work Offline healey100 Outlook 2 11-09-2010 09:38 AM

All times are GMT -7. The time now is 08:23 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc. is not affiliated with Microsoft