Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Roy Roy is offline
external usenet poster
 
Posts: 21
Default Making Macro2 start running after Macro1 ends

Hi
I managed to record & edit the two simple macros showing below.


Sub Macro1()
'
' Macro1 Macro
' Macro created 9/7/2008 by me
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[a-h]{3,}"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.MatchWildcards = False
End With
Selection.Find.Execute
End Sub


Sub Macro2()
'
' Macro2 Macro
' Macro recorded 9/7/2008 by me
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[a-fh][a-h]"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.ClearFormatting
With Selection.Find
.Text = "g[gh]"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.MatchWildcards = False
End With
Selection.Find.Execute
End Sub


Their job is to find an erroneous sequence of letters (represented here with
the letters a to h). After creating toolbar buttons for each of them, they
should be used in the following manner. The user clicks on Macro1 button; if
text is found, he should correct it manually (the correction should be
composed of 2 letters only). He keeps clicking on Macro1 button and making
corrections till no more results are found. After that, he moves to Macro2
button and does the same thing, making any needed corrections manually. Now
my question is, Is it possible to make Macro2 automatically start running
when Macro1 finds no more results, maybe by merging the 2 macros into one or
anything else?

PS: I had to add the '...Text = "" MatchWildcards = False ...' part
to each macro because it's the only way I found to automatically uncheck Use
Wildcards. The user is supposed to make normal, non-wildcard searches after
using the macros. So the part was added only to avoid confusing him.

Thanks in advance for your help.

  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Making Macro2 start running after Macro1 ends

On the face of it if you simply remove

End Sub


Sub Macro2()
'
' Macro2 Macro
' Macro recorded 9/7/2008 by me
'

from between the macros you will create one macro, but it might be better to
simply get the macro to do the whole task - which is somewhat vague and
complicated by the fact that the user must make a choice at each find.

If you know before you start what the combinations and their changes are to
be you can log them in a two column table with the words to search in column
1 and their replacements in column 2. Save the document with the table (here
saved as D:\My Documents\Test\changes.doc) and change the document path in
the macro to match then run the macro on your document.
http://www.gmayor.com/installing_macro.htm

Sub ReplaceFromTableList()

Dim ChangeDoc As Document, RefDoc As Document
Dim cTable As Table
Dim oldPart As Range, newPart As Range
Dim i As Long
Dim sFname As String

sFname = "D:\My Documents\Test\changes.doc"
Set RefDoc = ActiveDocument
Set ChangeDoc = Documents.Open(sFname)
Set cTable = ChangeDoc.Tables(1)
RefDoc.Activate
For i = 1 To cTable.Rows.Count
Set oldPart = cTable.Cell(i, 1).Range
oldPart.End = oldPart.End - 1
Set newPart = cTable.Cell(i, 2).Range
newPart.End = newPart.End - 1
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findText:=oldPart, _
ReplaceWith:=newPart, _
Replace:=wdReplaceAll, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Forward:=True, _
Wrap:=wdFindContinue
End With
End With
Next i
ChangeDoc.Close wdDoNotSaveChanges
End Sub


--

Graham Mayor - Word MVP

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


Roy wrote:
Hi
I managed to record & edit the two simple macros showing below.


Sub Macro1()
'
' Macro1 Macro
' Macro created 9/7/2008 by me
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[a-h]{3,}"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.MatchWildcards = False
End With
Selection.Find.Execute
End Sub


Sub Macro2()
'
' Macro2 Macro
' Macro recorded 9/7/2008 by me
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[a-fh][a-h]"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.ClearFormatting
With Selection.Find
.Text = "g[gh]"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.MatchWildcards = False
End With
Selection.Find.Execute
End Sub


Their job is to find an erroneous sequence of letters (represented
here with the letters a to h). After creating toolbar buttons for
each of them, they should be used in the following manner. The user
clicks on Macro1 button; if text is found, he should correct it
manually (the correction should be composed of 2 letters only). He
keeps clicking on Macro1 button and making corrections till no more
results are found. After that, he moves to Macro2 button and does the
same thing, making any needed corrections manually. Now my question
is, Is it possible to make Macro2 automatically start running when
Macro1 finds no more results, maybe by merging the 2 macros into one
or anything else?

PS: I had to add the '...Text = "" MatchWildcards = False ...'
part to each macro because it's the only way I found to automatically
uncheck Use Wildcards. The user is supposed to make normal,
non-wildcard searches after using the macros. So the part was added
only to avoid confusing him.

Thanks in advance for your help.



  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Roy Roy is offline
external usenet poster
 
Posts: 21
Default Making Macro2 start running after Macro1 ends

Thanks Graham

The problem with "joining" those two macros into one is that it makes Search
jump to the first 2 letters of any 3+ occurrences of the letters, in other
words it will use Macro2 to find what should be only found with Macro1. Any
3+ occurrence is erroneous, it should be dealt with first before moving to
any 2-letter erroneous occurrences.

For Macro2 searches, one can know beforehand what the change should be, so
the macro you provided comes in handy indeed. It will save a lot of time.
Thank you. But it's impossible to use it for macro1 searches, first because
only a human can know what the corrrect change should be in each and every
case (AI?) Second, if I were going to include every possible erroneous
occurrence of those letters, I would have 8x8x8=512 rows for the sequences of
3 letters; 8x8x8x8= 4096 rows for the sequences of four letters...

Sorry it's vague. But believe me, "ignorance is bliss" in this very case.
Thanks anyway.

"Graham Mayor" wrote:

On the face of it if you simply remove

End Sub


Sub Macro2()
'
' Macro2 Macro
' Macro recorded 9/7/2008 by me
'

from between the macros you will create one macro, but it might be better to
simply get the macro to do the whole task - which is somewhat vague and
complicated by the fact that the user must make a choice at each find.

If you know before you start what the combinations and their changes are to
be you can log them in a two column table with the words to search in column
1 and their replacements in column 2. Save the document with the table (here
saved as D:\My Documents\Test\changes.doc) and change the document path in
the macro to match then run the macro on your document.
http://www.gmayor.com/installing_macro.htm

Sub ReplaceFromTableList()

Dim ChangeDoc As Document, RefDoc As Document
Dim cTable As Table
Dim oldPart As Range, newPart As Range
Dim i As Long
Dim sFname As String

sFname = "D:\My Documents\Test\changes.doc"
Set RefDoc = ActiveDocument
Set ChangeDoc = Documents.Open(sFname)
Set cTable = ChangeDoc.Tables(1)
RefDoc.Activate
For i = 1 To cTable.Rows.Count
Set oldPart = cTable.Cell(i, 1).Range
oldPart.End = oldPart.End - 1
Set newPart = cTable.Cell(i, 2).Range
newPart.End = newPart.End - 1
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findText:=oldPart, _
ReplaceWith:=newPart, _
Replace:=wdReplaceAll, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Forward:=True, _
Wrap:=wdFindContinue
End With
End With
Next i
ChangeDoc.Close wdDoNotSaveChanges
End Sub


--

Graham Mayor - Word MVP

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


Roy wrote:
Hi
I managed to record & edit the two simple macros showing below.


Sub Macro1()
'
' Macro1 Macro
' Macro created 9/7/2008 by me
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[a-h]{3,}"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.MatchWildcards = False
End With
Selection.Find.Execute
End Sub


Sub Macro2()
'
' Macro2 Macro
' Macro recorded 9/7/2008 by me
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "[a-fh][a-h]"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.ClearFormatting
With Selection.Find
.Text = "g[gh]"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.MatchWildcards = False
End With
Selection.Find.Execute
End Sub


Their job is to find an erroneous sequence of letters (represented
here with the letters a to h). After creating toolbar buttons for
each of them, they should be used in the following manner. The user
clicks on Macro1 button; if text is found, he should correct it
manually (the correction should be composed of 2 letters only). He
keeps clicking on Macro1 button and making corrections till no more
results are found. After that, he moves to Macro2 button and does the
same thing, making any needed corrections manually. Now my question
is, Is it possible to make Macro2 automatically start running when
Macro1 finds no more results, maybe by merging the 2 macros into one
or anything else?

PS: I had to add the '...Text = "" MatchWildcards = False ...'
part to each macro because it's the only way I found to automatically
uncheck Use Wildcards. The user is supposed to make normal,
non-wildcard searches after using the macros. So the part was added
only to avoid confusing him.

Thanks in advance for your help.




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
trial ends on mirosoft 7 Pam Microsoft Word Help 1 February 6th 08 09:37 PM
can you help me to fine a word that ends with ds Jacknuz love you baby Microsoft Word Help 1 November 29th 07 04:11 AM
Ends of lines and breaks jezzica85 Microsoft Word Help 5 August 22nd 07 07:44 AM
How do I prevent the EULA from running every time I start Office 2 dollysowner Microsoft Word Help 6 June 10th 07 10:19 PM
AV running on start up of WORD John C. Harris Microsoft Word Help 4 July 31st 06 08:57 PM


All times are GMT +1. The time now is 10:02 PM.

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"