format tagging in word documents

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samnagpure
    New Member
    • Oct 2006
    • 2

    format tagging in word documents

    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
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by samnagpure
    TagBoldWords
    TagItalicWords ' if it is commented it works perfect, but i want both
    ' these procedures to be used simultaneously
    You might try adding DoEvents in between these two calls:

    TagBoldWords
    DoEvents
    TagItalicWords

    Comment

    • samnagpure
      New Member
      • Oct 2006
      • 2

      #3
      Originally posted by willakawill
      You might try adding DoEvents in between these two calls:

      TagBoldWords
      DoEvents
      TagItalicWords
      Thanks for the reply. I had tried that also but it didn't work, so I left it out.

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Originally posted by samnagpure
        Thanks for the reply. I had tried that also but it didn't work, so I left it out.
        Yeah. You need to give Word time to complete the process.
        Perhaps, after DoEvents, you can put in a timer or loop to create a time gap between the two calls.

        For i = 1 To 1000000
        stWasteTime = "Just wasting time"
        Next i

        Comment

        Working...