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 : wdDefaultFirstRecord , wdDefaultLastRecord etc..).

Enumerations starting by wd* are specific to Word VBA.

Is there a workaround for this ?

4 REPLIES 4

franlem2
Level 4
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
------------------------------

Quick styling tip, I find it's best to include the enumeration name as a constant before you use it. Otherwise, it can get very difficult for any future devs/maintainers to determine what 0 is referring to.

For example:
Const wdSendToNewDocument As Integer = 0
With doc.MailMerge
        .Destination = wdSendToNewDocument

Thanks for the link by the way. Handy reference and easier than manually looking things up through VBA.

------------------------------
Nicholas Zejdlik
RPA Developer
------------------------------

Hi Nicholas,

Indeed. This style is used in the code stage page ExportPDF the comes by default by the way.
Thanks for this suggestion and contribution.

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

AyshaM
Level 3
I am getting an error on the "GetDocument" part
where it says that "GetDocument is not declared it maybe be inaccessible due to its protection level"


Am I missing something? I double checked all the  references I have with the MS Word VBO provided object and they all seem to be in place.
13914.png


------------------------------
Aysha M
------------------------------