How to fix an Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

Jean-Pierre Ribeauville 80 Reputation points
2024-09-12T16:15:39.69+00:00

HI,
Started with a .docm template document , I'm invoking, from Powershell , Word to update fields read from a .csv to update letters sent to a lot of destinees , by the way of a VBA macro , then the .docx generated document is in a .pdf.
Then ,I got following error when invoking the macro ( as a consequence ,the .docx file isn't generated):
HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

Word call within powershell script :

$WORD.Documents.Open($DOCMACRO , $false, $false, $false, "", "", $true, "", "", 12, $null, $true, $false, 0, $false)

*$APP = $WORD.Application*	

*$APP.Run($MACRO, $CSVVAR, $REPWORK, $DOCWORDPU)*

*}*  

Macro used is this one :

Sub Macro1(CSV, WORK, PUBLISH)

'

' Macro1 Macro

'

'

ActiveDocument.MailMerge.MainDocumentType = wdFormLetters

*ActiveDocument.MailMerge.OpenDataSource Name:= _*

    *CSV, ConfirmConversions:=False, ReadOnly:= _*

    *False, LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="", _*

     *PasswordTemplate:="", WritePasswordDocument:="", WritePasswordTemplate:= _*

    *"", Revert:=False, Format:=wdOpenFormatAuto, Connection:="", SQLStatement _*

    *:="", SQLStatement1:="", SubType:=wdMergeSubTypeOther*

*With ActiveDocument.MailMerge*

    *.Destination = wdSendToNewDocument*

    *.SuppressBlankLines = True*

    *With .DataSource*

        *.FirstRecord = wdDefaultFirstRecord*

        *.LastRecord = wdDefaultLastRecord*

    *End With*

    *.Execute Pause:=False*

*End With*

*ChangeFileOpenDirectory WORK*

*ActiveDocument.SaveAs2 FileName:=PUBLISH, FileFormat:= _*

    *wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _*

    *:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _*

    *:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _*

    *SaveAsAOCELetter:=False, CompatibilityMode:=15*

*ActiveWindow.Close*

End Sub

I'm not expert in these domains , any idea to avoid to follow a bad track is welcome ^^
Thx for help.
J.P.

Word
Word
A family of Microsoft word processing software products for creating web, email, and print documents.
883 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,737 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,596 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.