MSWord not working?

Hi,
I am trying to merge multiple word files and found the following code, which i included in a “Invoke code” activity.

string[] filePaths = Directory.GetFiles(@"c:\Test\");

string[] documentsToMerge = filePaths;

string outputFileName = (@"C:\Test\Merge\Combined.docx");

MsWord.Merge(documentsToMerge, outputFileName, true);

My problem is now, that UI Path claims that “MsWord is not declared”. I have downloaded the word.activities package. But what am I doing wrong?

Thank you for the help in advance!

Best regards, Freja

Hi @freja.christensen

Try to add code line for using ms word:

using UiPath.Word;

string[] filePaths = Directory.GetFiles(@"c:\Test\");

string[] documentsToMerge = filePaths;

string outputFileName = @"C:\Test\Merge\Combined.docx";

WordDocument.Merge(documentsToMerge, outputFileName, true);

@freja.christensen

Please try with complete name space

Microsoft.Office.Interop.Word

cheers

I get the following error, when inserting the line “Unsing ##”. Where i substituted “##” whith both Microsoft.Office.Interop.Word and using UiPath.Word.

Hey @freja.christensen ,

  1. Make sure to install the word package i.e “UiPath.Word.Activities”
  2. Make sure to import namespace(UiPath.Word.Activities).
    3.Try using this code

Using System.Activities.Statements
Using UiPath.Word.Activities

Dim filePaths As String() = Directory.GetFiles(@"c:\Test")
Dim documentsToMerge As String() = filePaths
Dim outputFileName As String = @“C:\Test\Merge\Combined.docx”

Using wordApp As New WordApplicationClass
wordApp.Merge(documentsToMerge, outputFileName, True)
End Using

Hi Brian,

I have installed the word.Activities package and wrote the following code:


Using System.Activities.Statements
Using UiPath.Word.Activities
Dim filePaths As String() = Directory.GetFiles(DirectoryPath)
Dim documentsToMerge As String() = filePaths
Dim outputFileName As String = outputFileName

Using wordApp As New WordApplicationClass
wordApp.Merge(documentsToMerge, outputFileName, True)
End Using

And now i get the following error message:

Do you know, what the error mean?

@freja.christensen Try using this

filePaths As String() = Directory.GetFiles(@“c:\Test”)
documentsToMerge As String() = filePaths
outputFileName As String = @“C:\Test\Merge\Combined.docx”

Using wordApp As New WordApplicationClass
wordApp.Merge(documentsToMerge, outputFileName, True)
End Using

Hi @Brian_Mathew_Maben,

That seems to do the trick, now i only have the error message:
error BC30002: Type ‘WordApplicationClass’ is not defined.