#1   Report Post  
dk
 
Posts: n/a
Default Creating a macro

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
  #2   Report Post  
Graham Mayor
 
Posts: n/a
Default Creating a macro

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




  #3   Report Post  
dk
 
Posts: n/a
Default Creating a macro

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





  #4   Report Post  
Charles Kenyon
 
Posts: n/a
Default Creating a macro

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







  #5   Report Post  
dk
 
Posts: n/a
Default Creating a macro

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









  #6   Report Post  
Graham Mayor
 
Posts: n/a
Default Creating a macro

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



  #7   Report Post  
dk
 
Posts: n/a
Default Creating a macro

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




  #8   Report Post  
Graham Mayor
 
Posts: n/a
Default Creating a macro

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



  #9   Report Post  
Posted to microsoft.public.word.pagelayout
dk
 
Posts: n/a
Default Creating a macro

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




  #10   Report Post  
Posted to microsoft.public.word.pagelayout
Graham Mayor
 
Posts: n/a
Default Creating a macro

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





  #11   Report Post  
Posted to microsoft.public.word.pagelayout
dk
 
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




Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Macro that will insert a sentence when typing PCM Adah Microsoft Word Help 2 July 27th 05 08:01 PM
Creating A Macro To Create Address Labels Jerry Slocombe Mailmerge 9 July 11th 05 09:58 PM
Creating a macro that updates table fields Gail Microsoft Word Help 1 April 28th 05 11:56 PM
Suppressing AutoClose Macro when Creating TOC Spanning Multiple Do Barb R. Tables 2 March 30th 05 03:27 PM
need help creating macro to auto print Vaughn Microsoft Word Help 1 February 17th 05 06:28 PM


All times are GMT +1. The time now is 08:04 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"