Hi,
I have a following code to find the format tags in word document and insert some text over there. It works perfectly when I run only a single procedure individually i.e. commenting a call to either TagBoldWords or TagItalicWords.
Can anybody help me as to how we can go for it.
Thanks & Regards,
Sameer
Dim doc As New Word.Document
Dim appword As New Word.Applicatio n
Private Sub Command1_Click( )
Set appword = New Word.Applicatio n
Set doc = appword.Documen ts.Open("C:\AAA .doc")
doc.Content.Sel ect
TagBoldWords
TagItalicWords ' if it is commented it works perfect, but i want both
' these procedures to be used simultaneously
doc.SaveAs "C:\BBB.doc "
doc.Close
Set doc = Nothing
appword.Quit
Set appword = Nothing
Unload Me
End Sub
Sub TagBoldWords()
Selection.HomeK ey Unit:=wdStory
With Selection.Find
.Font.Bold = True
Do While (.Execute(findt ext:="", Forward:=True) = True) = True
With Selection
.InsertBefore Text:="<b>"
.Collapse Direction:=wdCo llapseEnd
'.Font.Bold = False
.TypeText Text:="</b>"
.Collapse Direction:=wdCo llapseEnd
End With
Loop
End With
End Sub
Sub TagItalicWords( )
Selection.HomeK ey Unit:=wdStory
With Selection.Find
.Font.Italic = True
Do While (.Execute(findt ext:="", Forward:=True) = True) = True
With Selection
.InsertBefore Text:="<i>"
.Collapse Direction:=wdCo llapseEnd
.Font.Italic = False
.TypeText Text:="</i>"
.Collapse Direction:=wdCo llapseEnd
End With
Loop
End With
End Sub
I have a following code to find the format tags in word document and insert some text over there. It works perfectly when I run only a single procedure individually i.e. commenting a call to either TagBoldWords or TagItalicWords.
Can anybody help me as to how we can go for it.
Thanks & Regards,
Sameer
Dim doc As New Word.Document
Dim appword As New Word.Applicatio n
Private Sub Command1_Click( )
Set appword = New Word.Applicatio n
Set doc = appword.Documen ts.Open("C:\AAA .doc")
doc.Content.Sel ect
TagBoldWords
TagItalicWords ' if it is commented it works perfect, but i want both
' these procedures to be used simultaneously
doc.SaveAs "C:\BBB.doc "
doc.Close
Set doc = Nothing
appword.Quit
Set appword = Nothing
Unload Me
End Sub
Sub TagBoldWords()
Selection.HomeK ey Unit:=wdStory
With Selection.Find
.Font.Bold = True
Do While (.Execute(findt ext:="", Forward:=True) = True) = True
With Selection
.InsertBefore Text:="<b>"
.Collapse Direction:=wdCo llapseEnd
'.Font.Bold = False
.TypeText Text:="</b>"
.Collapse Direction:=wdCo llapseEnd
End With
Loop
End With
End Sub
Sub TagItalicWords( )
Selection.HomeK ey Unit:=wdStory
With Selection.Find
.Font.Italic = True
Do While (.Execute(findt ext:="", Forward:=True) = True) = True
With Selection
.InsertBefore Text:="<i>"
.Collapse Direction:=wdCo llapseEnd
.Font.Italic = False
.TypeText Text:="</i>"
.Collapse Direction:=wdCo llapseEnd
End With
Loop
End With
End Sub
Comment