#1
|
|||
|
|||
Formatting with macros
I'm copying and pasting portions of text from a PDF to Word, so I created a macro to remove the line breaks at the end of each line and format & justify the paragraphs. Normally, what happens is I get a dialog after each operation asking if I want to search the rest of the document. I just select "No" and it goes to the next operation. But for some reason, as I was working, I stopped getting the dialogs and it just formatted the selected text automatically. I'm not sure why it did it or how to make it do it again. It was a lot easier when it did it automatically. Anyone know what might have made it do this or if there's a way to make it do it all the time? Picture of dialog attached. Word 2007. |
#2
|
|||
|
|||
I suspect what will be needed is not a picture of the dialog but the text of your macro. You can find the text of the macro by pressing Alt+F11 to give you the vba editor. It is probably in the New Macros module of your Normal template.
|
#3
|
||||
|
||||
See the macro here for a comprehensive solution: https://www.msofficeforums.com/word/...html#post32907
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Thanks for the replies, and sorry for posting in the wrong forum. The text of the macro in question is below. I think that's it anyway, I'm fairly new at all this. Can I edit it in some way to prevent the dialogs? If so, please give instructions if possible. I've never done it before but could probably do it if guided through. Thanks a lot.
Code:
Sub Macro2() ' ' Macro2 Macro ' Ctrl+ M Justify several paragraphs ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "zzz^p" .Replacement.Text = "zzz" .Forward = True .Wrap = wdFindAsk .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "^p" .Replacement.Text = " " .Forward = True .Wrap = wdFindAsk .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll With Selection.Find .Text = "zzz" .Replacement.Text = "^p^p" .Forward = True .Wrap = wdFindAsk .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify End Sub Last edited by macropod; 05-13-2012 at 02:49 PM. Reason: Added code tags & formatting |
#5
|
||||
|
||||
Hi Walt,
Did you try the macro in the link I posted? The macro you posted looks like it's only one of a series you're using for your reformatting. Aside from the fact that it has a lot of redundant code (if you look at the macro code in the link I posted you can see how much it can be simplified), the reason you're getting the prompts is that your code has '.Wrap = wdFindAsk' (three times). If you change that to '.Wrap = wdFindStop', it'll simply stop searching at the end of whatever's selected. Alternatively, if you change it to '.Wrap = wdFindContinue', it will continue without asking.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Thanks a million macropod. Replacing with '.Wrap = wdFindStop' produced the desired outcome, no more interuptions, yeah!
You're right, I've got several macros for different operations. This particular one performs three operations. I did look at yours but I wasn't sure if it would work with the document I'm working with. The only way I know to make macros is to record them through the Developer tab, so I wouldn't know how to do it from just the code, at this point anyway. I've got a book with a couple of chapters on writing macros in Word so I might check it out. I'm not sure that's something I really wanna tackle right now, but I'm sure you're right, it would probably simplify life in the long run. I'm not sure why Word would temporarily skip over those dialogs, pretty weird. But it doesn't really matter now I guess. Again, much appreciated. |
#7
|
||||
|
||||
It doesn't take long to try ...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
Quote:
One of the best ways I've found to learn vba is to look at code written by a very good programmer and try stepping through it to see what it does. The code put together by the macro recorder can be a start but it is never well written. Many functions in Word cannot be captured by the recorder. In case you haven't guessed, Paul is a very good programmer. A very good book IMHO is Writing Word Macros by Steve Roman, from O'Reilly even though I think it was written for Word 2000. As far a s time goes, if you need macros to do your work, try investing an hour a week in learning. It will repay you very quickly. Last edited by Charles Kenyon; 05-15-2012 at 05:57 AM. Reason: clean up formatting |
#9
|
||||
|
||||
Competent, may be, but I wouldn't say 'very good'.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA macros | tays01s | Word VBA | 6 | 08-03-2011 09:42 PM |
Macros | Steveg | Word VBA | 0 | 08-18-2010 04:04 PM |
Macros | Desertwrangler | Word VBA | 6 | 06-25-2010 07:06 AM |
macros | trancetheory | Outlook | 0 | 05-11-2010 09:31 AM |
Macros | krdzal | Excel | 1 | 04-06-2010 07:43 AM |