B
bjr
I'm attempting to build into an existing Word macro to search for a specific
code within a table that's being used as a mail merge data source. If the
code is found, activate a separate document to copy specific information
related to that code back to the table...that part's working.
I don't know how tell it NOT to activate the separate document if the code
isn't found. At that point, I need it to continue to the next code. The
macro looks at for about 100 different codes that MAY be in the table.
Here's a piece of my current macro ("regappt.txt" is the data source that
will be saved as a .docx at the end of the macro, "PandCCode.for macro
reference.docx" is the document that contains all of the codes with their
associated text):
With Selection.Find
.Text = "P006,"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Documents.Open FileName:="PandCCode.for macro reference.docx"
Selection.Find.ClearFormatting
With Selection.Find
.Text = "P006,"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
Selection.Copy
Windows("REGAppt.txt").Activate
Selection.PasteAndFormat (wdPasteDefault)
Selection.Find.ClearFormatting
With Selection.Find
.Text = "P009,"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Windows("PandCCODE.FOR MACRO REFERENCE.docx").Activate
Selection.Find.ClearFormatting
With Selection.Find
.Text = "P009,"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
Selection.Copy
Windows("REGAppt.txt").Activate
Selection.PasteAndFormat (wdPasteDefault)
Selection.Find.ClearFormatting
code within a table that's being used as a mail merge data source. If the
code is found, activate a separate document to copy specific information
related to that code back to the table...that part's working.
I don't know how tell it NOT to activate the separate document if the code
isn't found. At that point, I need it to continue to the next code. The
macro looks at for about 100 different codes that MAY be in the table.
Here's a piece of my current macro ("regappt.txt" is the data source that
will be saved as a .docx at the end of the macro, "PandCCode.for macro
reference.docx" is the document that contains all of the codes with their
associated text):
With Selection.Find
.Text = "P006,"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Documents.Open FileName:="PandCCode.for macro reference.docx"
Selection.Find.ClearFormatting
With Selection.Find
.Text = "P006,"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
Selection.Copy
Windows("REGAppt.txt").Activate
Selection.PasteAndFormat (wdPasteDefault)
Selection.Find.ClearFormatting
With Selection.Find
.Text = "P009,"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Windows("PandCCODE.FOR MACRO REFERENCE.docx").Activate
Selection.Find.ClearFormatting
With Selection.Find
.Text = "P009,"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCell
Selection.Copy
Windows("REGAppt.txt").Activate
Selection.PasteAndFormat (wdPasteDefault)
Selection.Find.ClearFormatting