none
Manage Word Document into Outlook using VBA RRS feed

  • Question

  • Dear all,

    After the migration from Office 2003 to Office 2007, I'm encountering a problem running a Outlook VBA macro that opens a word document and execute a find and replace.

    Here below the code fragment:

    Public Sub print_fax(sender As Employee, amount, paymentdate, valuedate)
        Dim wordApp As word.Application
        Dim fax As word.Document
        Set wordApp = New word.Application
        wordApp.Visible = False
        Set fax = wordApp.Documents.Open(basepath & "model.doc", False, True)
        
        With fax.Content.Find
            .ClearFormatting
            .Text = "__TODAY__"
            .Replacement.ClearFormatting
            .Replacement.Text = Format(Date, "dd MMMM yyyy")
            .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
        End With

    The macro was working properly on Outlook 2003 but now when the execution reaches the line

    fax.Content.Find.ClearFormatting

    I get the following error message:

    Has anybody found my same problem? Could you please help me to find a solution?

    Thank you very much for your support.

    Kind rergards,
    Maurizio

    Friday, October 4, 2013 1:30 PM