I have the following code and I wanted to every word "ARTICLE" that is founded in the word file add a number in order to create a numbering (e.g: ARTICLE 1 : , ARTICLE 2 : , ARTICLE 3 , etc)
But the following code is not following an order and can't recognize the words that are in bold
But the following code is not following an order and can't recognize the words that are in bold
VBA Code:
j
Sub AddNumberToName()
'Declare variables
Dim doc As Object
Dim range As Object
Dim i As Integer
'Open the Word document
Set doc = CreateObject("Word.Application")
doc.Documents.Open ("C:\UserData\Documents\article.docx")
'Get the range of the document
Set range = doc.ActiveDocument.Content
'Loop through each word in the range
For i = 1 To range.Words.Count
'Check if the word is "Name"
If range.Words(i) = "ARTICLE" Then
'Add the number to the word
range.Words(i).Text = "ARTICLE " & (i \ 2) + 1 & " :"
End If
Next i
'Save and close the document
doc.ActiveDocument.Save
doc.ActiveDocument.Close
'Quit Word
doc.Quit
End Sub