Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-12-2012, 08:51 AM
WaltR WaltR is offline Windows Vista Office 2007
Competent Performer
Formatting with macros
 
Join Date: Dec 2010
Posts: 123
WaltR is on a distinguished road
Default 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.
Attached Images
File Type: jpg 01.jpg (39.5 KB, 11 views)
Reply With Quote
  #2  
Old 05-12-2012, 02:16 PM
Charles Kenyon Charles Kenyon is offline Formatting with macros Windows Vista Formatting with macros Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

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.
Reply With Quote
  #3  
Old 05-12-2012, 02:52 PM
macropod's Avatar
macropod macropod is offline Formatting with macros Windows 7 64bit Formatting with macros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See the macro here for a comprehensive solution: https://www.msofficeforums.com/word/...html#post32907
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 05-13-2012, 12:44 PM
WaltR WaltR is offline Windows Vista Office 2007
Competent Performer
Formatting with macros
 
Join Date: Dec 2010
Posts: 123
WaltR is on a distinguished road
Default

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
Reply With Quote
  #5  
Old 05-13-2012, 02:53 PM
macropod's Avatar
macropod macropod is offline Formatting with macros Windows 7 64bit Formatting with macros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #6  
Old 05-13-2012, 04:28 PM
WaltR WaltR is offline Windows Vista Office 2007
Competent Performer
Formatting with macros
 
Join Date: Dec 2010
Posts: 123
WaltR is on a distinguished road
Default

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.
Reply With Quote
  #7  
Old 05-13-2012, 04:31 PM
macropod's Avatar
macropod macropod is offline Formatting with macros Windows 7 64bit Formatting with macros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by WaltR View Post
I did look at yours but I wasn't sure if it would work with the document I'm working with.
It doesn't take long to try ...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 05-15-2012, 05:55 AM
Charles Kenyon Charles Kenyon is offline Formatting with macros Windows Vista Formatting with macros Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by WaltR View Post
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.

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
Reply With Quote
  #9  
Old 05-15-2012, 06:28 PM
macropod's Avatar
macropod macropod is offline Formatting with macros Windows 7 64bit Formatting with macros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Charles Kenyon View Post
In case you haven't guessed, Paul is a very good programmer.
Competent, may be, but I wouldn't say 'very good'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting with macros VBA macros tays01s Word VBA 6 08-03-2011 09:42 PM
Macros Steveg Word VBA 0 08-18-2010 04:04 PM
Formatting with macros Macros Desertwrangler Word VBA 6 06-25-2010 07:06 AM
macros trancetheory Outlook 0 05-11-2010 09:31 AM
Formatting with macros Macros krdzal Excel 1 04-06-2010 07:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:56 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft