I need to get the code from a merge document and add it into the file name for identification.
The merge document looks as follows:
I need to extract the code after the hyphen on the 7th line of the document.
I have a recorded macro, but adapting it is a learning curve.
Any help with the code will be appreciated.
Code: Select all
Sub GetCode()
Dim x As Integer
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=6
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
'x = Selection.Characters.Count '< Get count of character in line for MID??
Selection.Find.ClearFormatting
With Selection.Find
.Text = "-"
.Forward = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend '< Maybe a MID function or something?
'Store the code in a variable that I can use in further code after this...
End Sub