A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Page Layout
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Creating a macro



 
 
Thread Tools Display Modes
  #11  
Old November 17th, 2005, 04:36 PM posted to microsoft.public.word.pagelayout
external usenet poster
 
Posts: n/a
Default Creating a macro

OK it worked
Now, how can we prevent forom changing when "mr" appears in middle of a
word ,also we used to run a find replace bettween last name and add. by using
this command find ([a-z])([a-z]) ([ ])([0-9])([0-9])([\!])REPLACE\1\2\3\4\5
can we still use this in a macro?How?

"Graham Mayor" wrote:

That line does not appear in the code I posted so I haven't a clue what it
is you are doing. You seem to have some other macro code in there. Rename
normal.dot to oldnormal.dot and start again with a blank sheet.

As for posting - see http://www.gmayor.com/MSNews.htm

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


dk wrote:
this is the line with different color:
' Purpose: remove any of the characters in sBadChars from vPhrase
also alot of times we have problems to reply to post why?

"Graham Mayor" wrote:

Open the macro editor (ALT+F11) and see which line is flagged in
error. If you have not used macros before there should only be this
code in the editor and the errant line will be highlighted.
From the Run menu - click reset and try again. Do you still get the
error? Which line?

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


dk wrote:
we went to macro created new macro we copied the following
Sub Commas()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Mrs([!,])"
.Replacement.Text = "Mrs,\1"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub
with hit run, again we got the same error
"compile error line number" etc.
"Graham Mayor" wrote:

Replace all that lot with:

Sub Commas()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Mrs([!,])"
.Replacement.Text = "Mrs,\1"
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub

This will replace all instances of Mrs with Mrs, unless there is
already a comma present.
If you want to do the same for eg Mr and Dr then you can either
daisychain the macros or use an array to present the items eg

Sub ReplaceMyList()
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long

vFindText = Array("Mrs([!,])", "Mr([!s,])", "Dr([!,])")
vReplText = Array("Mrs,\1", "Mr,\1", "Dr,\1")
With Selection.Find
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
.Format = True
.MatchCase = True

For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText(i)
.Execute replace:=wdReplaceAll
Next i
End With
End Sub

See http://www.gmayor.com/installing_macro.htm

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




dk wrote:
this is the macro


With Selection.Find
.ClearFormatting
.Text = "Mrs"
With .Replacement
.ClearFormatting
.Text = "Mrs,"
End With
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
.Execute replace:=wdReplaceAll
End With


Sub AddinInit()
'
' AddinInit Macro
' Macro created 10/31/2005 by David Katz
'

End Sub
Sub commas()
'
' commas Macro
' Macro recorded 10/31/2005 by David Katz
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Mrs"
.Replacement.Text = "Mrs,"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute replace:=wdReplaceAll
End Sub


"Charles Kenyon" wrote:

Alt-F11 opens the vba editor interface.

You may want to look at:
http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm and
http://word.mvps.org/FAQs/MacrosVBA/...csIn15Mins.htm.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version
of Microsoft's Legal Users' Guide)
http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is
awesome! --------- --------- --------- --------- ---------
---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"dk" wrote in message
...
were can we find the code ? we are new in the macro we are just
recording and
running the find replace function in regular mode


"Graham Mayor" wrote:

As you have not included the errant code in your message it is
impossible to
troubleshoot it, but there's clearly a syntax error. The macro
recorder does
not handle all aspects of the replace tool properly and some
replace functions will have to be coded manually - and yes you
can have several replace functions in a single macro. - paste
the code into your reply and let us know what it is supposed to
do!

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org




dk wrote:
We Have never used a macro, but we have multiple documents
that we have to do same find & replace for ex; adding commas
before address etc. we tryied recording a macro & using the
find and replace fuction we ran it in regular mode then we
stopped the macro and tried running the macro in the same
file we received a error compile error ; expected line number
or label number at end of statement what should we do over
here
Also we would like to have several find & replace in one macro
is that possible




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Macro to generate automated email Shery General Discussion 0 October 4th, 2005 03:41 PM
Creating a macro commad to shift selected rows to the right next c Shifting of Multiple Row to the right General Discussion 1 September 15th, 2005 03:31 AM
Creating a macro that updates table fields Gail General Discussion 1 April 28th, 2005 11:56 PM
word error mac General Discussions 1 May 6th, 2004 08:14 AM
Creating a Relative Macro Mar Worksheet Functions 3 October 13th, 2003 01:50 AM


All times are GMT +1. The time now is 03:39 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.