cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass variables wd* specific to MS Word into code stage

franlem2
Level 4

Hi,

I am trying to pass some enumerations from Word VBA into a code stage using the Word VBO.

MS Word internal code is using some enumerations that are not recognised by VB code stages.

For example :

Dim doc as Object = GetDocument(Handle,documentname)
    doc.MailMerge.OpenDataSource (DataSourceName, SQLStatement:="SELECT * FROM `ABC$`")

    With doc.MailMerge
        .Destination = wdSendToNewDocument
        
    End With

Error message is wdSendToNewDocument is not declared. It may be inaccessible due to its protection level.
This issue only happen with enumerations starting by wd*  (e.g : wdSendToNewDocument, wdDefaultFirstRecord , wdDefaultLastRecord etc..).

Enumerations starting by wd* are specific to Word VBA.

Is there a way to make these wd* work in a code stage ?

​​
2 REPLIES 2

LucaValente
Staff
Staff

Hi François,

I haven't tested the code but I tried to add the "Microsoft.Office.Interop.Word.dll" to the External References in the Code Options of the Initialise action, also I added the "Microsoft.Office.Interop.Word" namespace in the Namespace Imports list. Then I tried to use "WdMailMergeDestination.wdSendToNewDocument" to my code and the Check Code doesn't give any error. You might want to try, I can't guarantee it works! 

You have to add the "Microsoft.Office.Interop.Word.dll" manually using the Browse button. In my case it was under a "C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Word\15.0.0.0 ........" folder



------------------------------
Luca Valente
Senior Product Consultant
Blue Prism
America/New_York
------------------------------

Hi Luca,

Thank you for your suggestion. It did not work for my process unfortunately.

I actually replaced each enumeration wd* by the corresponding integer value, available in the Office Dev Center and this way it worked.

For example :
 .Destination = wdSendToNewDocument

can be replaced by...
.Destination = 0

If someone has the same question the full mapping Enumeration - Integer value is here:
https://docs.microsoft.com/en-us/office/vba/api/word(enumerations)


------------------------------
François Lemarié
Blue Prism Consultant
Addstones-Gfi
Europe/Paris
------------------------------