Thanks so much for your help with this earlier! This time I would like to do a little more with this macro. You showed me how to add an auto number, but I also want to add the first capital letter of every word on the line.
Here is an example of how the data looks originally:
1 Class in COER 112
Label "Microcomputer Operating Systems";
1 Class in COER 116
Label "Microcomputer Hardware";
1 Class in COER 125
Label "Seminar";
1 Class in NETW 170
Label "Intro to Information Security";
What I basically want to do is find the string (Label ") and replace it with (Label X "), where the "X is an incremental counter. THEN take the first CAPITAL letter of each word that follows until you run into the ";" character, or End of Line.
Therefore, the end result should look like this:
1 Class in COER 112
Label 1MOS "Microcomputer Operating Systems";
1 Class in COER 116
Label 2MH "Microcomputer Hardware";
1 Class in COER 125
Label 3S "Seminar";
1 Class in NETW 170
Label 7IIS "Intro to Information Security";
Thanks to the awesome amount of help given by Andreas Killer, below, I've listed the code down that only finds the "Label" string, then adds the counter. What I'm looking to do now is add the functionality to extract the first Capital letter of every word
that follows the "label string all the way to the end of the line, OR until it runs into the ";" character, whichever is easier.
Sub FindReplace(ByVal FName As String)
Dim D As Document
Dim R As Range
Dim i As Integer
'Open the document
Set D = Documents.Open(FName)
'Get the range for the whole document
Set R = D.Content
'Search for the keyword
Do While R.Find.Execute("Label """)
'Note: Find.Execute modifies the object R to the location of the keyword!
'Note: InsertAfter expand the object R to include the text to be inserted!
'Find the " and replace it with null
'R.Find.Execute (Replace("Label " & Chr(34), Chr(34), ""))
R.Find.Execute (Replace("Label """, """", ""))
'Insert the counter after the keyword
i = i + 1
R.InsertAfter i & " "
'Setup object R to the position after the keyword up to the end of the document
R.SetRange R.End, D.Content.End
Loop
'Save and close
D.Close True, wdOriginalDocumentFormat
End Sub
Any ideas on the code to create the additional functionality?