Consulting

Results 1 to 3 of 3

Thread: Calling Word macro from Excel macro

  1. #1
    VBAX Newbie
    Joined
    Jul 2007
    Posts
    2
    Location

    Calling Word macro from Excel macro

    All,

    I have an Excel script that goes through a file share and opens up published Word documents in order to find and replace text. Unfortunately it doesnt seem to do the job with below:

    Set wrd = CreateObject("Word.Application")
    wrd.DisplayAlerts = wdAlertsNone
    wrd.Visible = True
    While strCurFile <> ""
    strFullFileName = strTgtPath & strCurFile
    Range("C12").Value = strFullFileName
    Range("C14").Value = Range("C14").Value + 1
    On Error Resume Next


    Set MyDoc = wrd.Documents.Open(strFullFileName)

    MyDoc.Select


    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
    .Text = "Crisis Response Leader"
    .Replacement.Text = "Immediate Response Leader"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    If MyDoc.Find.Found = True Then
    Range("C26").Value = Range("C26").Value + 1
    shtFileListTab.Cells(k, 1).Value = MyDoc.FullName
    End If

    k = k + 1
    MyDoc.Close Savechanges:=wdSaveChanges


    strCurFile = Dir()

    Wend
    wrd.Quit
    Set wrd = Nothing
    Set MyDoc = Nothing

    The highlighted portion of the code does work if run within Word. Is there some way to call a Word procedure from the Excel script?

    Dan

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Just set a reference to Microsoft Word
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    VBAX Mentor Brandtrock's Avatar
    Joined
    Jun 2004
    Location
    Titonka, IA
    Posts
    399
    Location
    Quote Originally Posted by Oorang
    Just set a reference to Microsoft Word
    This article illustrates how to add a reference manually or programmatically. The reference in the article is NOT to Word, but the procedure remains the same (except for the GUID number). To get a list of these numbers that you might have occasion to use frequently, this KB will list them for any references checked manually before the macro is run.

    Hope this helps,
    Brandtrock




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •