Syntax error calling MailMerge.OpenDataSource

L

Laurel

This is the only statement in a macro I've created. If I use only the first
parameter (leave off the format parameter, 0), it works fine. If I add the
zero, I get a syntax error. What am I doing wrong?

ActiveDocument.MailMerge.OpenDataSource
("C:\OpenDataSource\OpenDataSource.xls",0)
 
D

Doug Robbins - Word MVP

Probably each of the wdOpenFormat constants does have a unique numeric
value. As I do not know what they are and therefore cannot say whether 0 is
a valid value, why not use the format that you want using its text format.
The following from the Visual Basic Help file gives the the WdOpenFormat
constants:

Format Optional Variant. The file converter used to open the document.
Can be one of the WdOpenFormat constants. To specify an external file
format, use the OpenFormat property with the FileConverter object to
determine the value to use with this argument.

WdOpenFormat can be one of these WdOpenFormat constants.
wdOpenFormatAllWord
wdOpenFormatAuto Default.
wdOpenFormatDocument
wdOpenFormatEncodedText
wdOpenFormatRTF
wdOpenFormatTemplate
wdOpenFormatText
wdOpenFormatUnicodeText
wdOpenFormatWebPages
wdOpenFormatXML


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

Laurel

Well, I tried this but still got the same error. wdOpenFormatDocument has a
value of 0.
ActiveDocument.MailMerge.OpenDataSource
("C:\OpenDataSource\OpenDataSource.xls", wdOpenFormatDocument)

I tried this and it worked.
ActiveDocument.MailMerge.OpenDataSource _
Name:="C:\OpenDataSource\OpenDataSource.xls", _
Format:=wdOpenFormatAuto

Is it actually the case that position-based parameters don't work in Word at
all? The reason this is important is that I wanted to demonstrate that the
following statement, which used to work in PowerBuilder for Word 9.0, and
which no longer works in 11.0, DOES work in a non-PowerBuilder environment.
So it's important that I be able to use positioning instead of naming.

ole_word_file.MailMerge.OpenDataSource
("C:\OpenDataSource\OpenDataSource.xls",0,FALSE,TRUE,FALSE,FALSE,"","",FALSE,"","","Entire
Spreadsheet")
 
D

Doug Robbins - Word MVP

Sorry, I don't know.

However, that's the first indication that I have seen of PowerBuilder
working with anything. There's certainly been a lot of people come to these
newsgroups with problems with it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

Laurel

I got this answer from Peter Jamieson in another forum. I'm reposting it
here in case anyone else was looking at this and wondering about the answer.

Looking at your post in the "beginners" forum, one problem is that you're
using

Activedocument.Mailmerge.OpenDataSource (filename,0)

when VBA wants

Activedocument.Mailmerge.OpenDataSource filename,0

because you are making a method call, not a function call.

The reason

Activedocument.Mailmerge.OpenDataSource (filename)

works is because (filename) is a valid expression. (Actually I'm not an
expert on this stuff so don't take my word for it, but I think you will
discover that the following call works as well:

Activedocument.Mailmerge.OpenDataSource (filename),(0)

The call I made when testing was more like:


ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
ActiveDocument.MailMerge.OpenDataSource _
"C:\mywb\Book1.xls", _
wdOpenFormatAuto, _
False, False, False, False, _
"", "", _
False, _
"", "", _
"Entire Spreadsheet", _
"", "", False, wdMergeSubTypeWord2000
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top