Z
z
Hi;I've searched web and group and can't find an answer to this
question, or if I did I don't recognize it as the answer.... I think
it's simple, but it's beyond my siimple "record a macro and edit it"
skill set.
Anyway, I've got a bunch of files to process. All want to do is copy
the top line of each file (which changes from file to file) plus a
terminating slash, and then replace every instance of a target string
(always the same in every file although the number of times the target
appears may be different ) with that copied text.
I recorded a macro which does fine, except that where I put the
replacement text into the dialog box using "paste", of course the
macro hardcodes that string, for instance "firstlineoffirstfile/"
verbatim into the VBA code, so when I run it on another file with,
say, a first line of "firstlineofsecondfile", it copies it nicely but
then replaces the target string with "firstlineoffirstfile/" which it
hardcoded when i recorded it on the first file.
so, simply enough I hope; where the recorded macro code has
Selection.Find.Execute
Selection.TypeParagraph
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdPasteDefault)
Selection.TypeText Text:="/"
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "target"
.Replacement.Text = _
"firstlineofthisfile/"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
I just want it to replace "firstlineofthisfile/" with the current
contents of
the clipboard which got copied up in line 7
TIA!!!
question, or if I did I don't recognize it as the answer.... I think
it's simple, but it's beyond my siimple "record a macro and edit it"
skill set.
Anyway, I've got a bunch of files to process. All want to do is copy
the top line of each file (which changes from file to file) plus a
terminating slash, and then replace every instance of a target string
(always the same in every file although the number of times the target
appears may be different ) with that copied text.
I recorded a macro which does fine, except that where I put the
replacement text into the dialog box using "paste", of course the
macro hardcodes that string, for instance "firstlineoffirstfile/"
verbatim into the VBA code, so when I run it on another file with,
say, a first line of "firstlineofsecondfile", it copies it nicely but
then replaces the target string with "firstlineoffirstfile/" which it
hardcoded when i recorded it on the first file.
so, simply enough I hope; where the recorded macro code has
Selection.Find.Execute
Selection.TypeParagraph
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdPasteDefault)
Selection.TypeText Text:="/"
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "target"
.Replacement.Text = _
"firstlineofthisfile/"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
I just want it to replace "firstlineofthisfile/" with the current
contents of
the clipboard which got copied up in line 7
TIA!!!