Invoke Method ‘SaveAs’ method

I am trying to use the Invoke Method for saving a word document without having to use the invoke code activity due to restrictions set by my workplace. I have the following variables created and am trying to save the word document after it sends the text to Word

wordApp = New Microsoft.Office.Interop.Word.ApplicationClass
wordApp.Visible = True
docPath = filePath + “\” + “test.docx”
doc = wordApp.Documents.Add()
doc.Content.Text = System.IO.ReadAllText(strTxt)

How do I use the Invoke Method to “Save” the document

Hi @j1osu2006 ,
Step 1: Create a new Invoke Method activity
Step 2: Set the TargetObject to doc (your Word document object)
Step 3: Set the MethodName to “SaveAs2”
Step 4: Add a parameter:
Direction: In
Type: String
Value: docPath
This will call doc.SaveAs2(docPath) internally.

Step 5(optional) To clean up resources, use two more Invoke Method activities:

  • Close the document:
    • TargetObject: doc
    • MethodName: Close
  • Quit Word:
    • TargetObject: wordApp
    • MethodName: Quit

If this solves your query kindly, close this case by marking it as solution.

Cheers!

I’m getting the following error on the invoke method for SaveAs2:

Document does not have a public instance method named SaveAs2 matching the parameter type, generic type arguments, and generic type constraints supplied to InvokeMethod ‘invoke Method”.

Hi @j1osu2006

Can you change the Parameter type to System.Object and check if its working?

I’m still getting the same error. My doc variable is set to:

doc = wordApp.Documents.Add()

Can you provide screenshots on your end for me to see that’s it’s working on your end?

your code look good, can you try

  • MethodName: SaveAs instead of SaveAs2?

I tried both with the SaveAs and still receive the same error.

I’m getting the same error, even used the Save, SaveAs and SaveAs2 method name also passed right parameters (docPath also file format).

Maybe try writing the code in the invoke code activity to complete your requirement.?

@j1osu2006

Why not simply use word activities?

cheers