#1
|
|||
|
|||
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? |
#2
|
||||
|
||||
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: https://www.msofficeforums.com/word-...tml#post127202. 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.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
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 |