Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

Need help writing macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe Payne - 16 Aug 2005 11:57 GMT
I appologize for posting in two newsgroups. I didn't know I wasn't
supposed to until I had already posted the second message.

Need help writing macro
I frequently receive emails that I forward on to other people. Because
some of them are forwarded to me the text is sometimes scattered and
contains symbols that need to be removed. I have created a macro to
remove the symbols but I can’t figure out how to fix the formatting. I
want to consolidate the text in each paragraph, removing the blank
spaces, and then seperate the paragraphs with double blank lines.The
macro would also need to wrap the lines in each paragraph.  I may not
be using the correct terminology so I will show an example below. This
would be what is left after I remove the symbols.
------------------------------------------------------------------------------------------------------------

On a visit to my wife's native
 England for our honeymoon, we arrived at London's Gatwick Airport.
Tania headed for the British- passport control line while I, an
American, waited in the     foreigners' line.       When my turn came,
the customs officer asked me the                   purpose of my
visit.     "Pleasure," I replied. "I'm on my honeymoon." The officer
looked first to one side of me, then the other.         "That's very
interesting, sir," he            
said as he stamped my passport. "Most men bring their wives with
them."

                          One afternoon shortly after I was married,
the phone rang. "Collect call from Dorothy," said the operator. "Will
you         accept the charges?" Because I couldn't think of anyone
named Dorothy,    I said no and hung up. The phone rang again a moment
later. "Hi, Brenda, it's Dorothy," said the       familiar voice.
"Your mother-in- law."
-------------------------------------------------------------------------------------------------------------------

And this is what I want it to look like after running the macro.

On a visit to my wife's native England for our honeymoon, we arrived
at London's Gatwick Airport. Tania headed for the British- passport
control line while I, an American, waited in the foreigners' line.
When my turn came, the customs officer asked me the purpose of my
visit. "Pleasure," I replied. "I'm on my honeymoon." The officer
looked first to one side of me, then the other. "That's very
interesting, sir," he said as he stamped my passport. "Most men bring
their wives with them."

One afternoon shortly after I was married, the phone rang. "Collect
call from Dorothy," said the operator. "Will you accept the charges?"
Because I couldn't think of anyone named Dorothy, I said no and hung
up. The phone rang again a moment later. "Hi, Brenda, it's Dorothy,"
said the familiar voice. "Your mother-in- law."
-------------------------------------------------------------------------------------------------------------------

Any help would be greatly appreciated. Thanks.  Joe
Chuck Henrich - 16 Aug 2005 12:56 GMT
Hi Joe

You didn't say whether you're fixing the formatting in Outlook or Word.  
Assuming you're working in Word and that you're manually selecting the text
to be reformatted, the following code replaces returns and extra spaces.  The
extra spaces search-replace uses wildcards, which you might want to play
around with.  The FlushFind portion of the code cleans out search-specific
settings in the replace dialog.  There are fancier, more efficient ways of
doing this, but hopefully the following code is a starting point for you to
get the basic concepts.

Sub RemoveReturnsSpaces()

With Selection.Find
   .Text = "^p"
   .Replacement.Text = ""
   .Forward = True
   .Wrap = wdFindStop
   .Format = False
   .MatchCase = False
   .MatchWholeWord = False
   .MatchWildcards = False
   .MatchSoundsLike = False
   .MatchAllWordForms = False
   .Execute Replace:=wdReplaceAll
End With

GoSub FlushFind

   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
       .Text = " {2,}"
       .Replacement.Text = " "
       .Forward = True
       .Wrap = wdFindStop
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchAllWordForms = False
       .MatchSoundsLike = False
       .MatchWildcards = True
   End With
   Selection.Find.Execute Replace:=wdReplaceAll

GoSub FlushFind

Exit Sub

FlushFind:

With Selection.Find
       .ClearFormatting
       .ClearAllFuzzyOptions
       .Replacement.ClearFormatting
       .Text = ""
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindStop
       .Format = False
       .MatchCase = False
       .MatchWholeWord = False
       .MatchWildcards = False
       .MatchSoundsLike = False
       .MatchAllWordForms = False
       .Execute
End With

Return

End Sub

HTH
Signature

Chuck Henrich
www.ProductivityApps.com

> I appologize for posting in two newsgroups. I didn't know I wasn't
> supposed to until I had already posted the second message.
[quoted text clipped - 49 lines]
>
> Any help would be greatly appreciated. Thanks.  Joe
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.