Click to See Complete Forum and Search --> : Strange keyword problem with Excel macro


August 18th, 1999, 09:05 AM
I wrote an application in Visual Basic that uses an automation interface. There is a method defined in the interface called "Print" which is a keyword. To solve this problem, I put square brackets around the word when I called it, like this:

pDoc.[Print] " ", txtFirst, txtLast, chkNotes, chkAttributes, chkForm, chkAnnotations

and it worked fine.

Now, I am pretty much writing the same application, but in Excel using macros. Now, when I want to call the same Print method, the exact same way I called it in the other application, it doesn't work!

The error I get is:

Expected: "(" and it highlights the first parameter, which is a string. I have tried putting " " and a variable name in for the string, but it still doesn't work.

Does anyone know if there is something different I have to do with keywords when I am using Visual Basic with Excelt marcros?

Thanks!

cricket
August 23rd, 1999, 07:28 AM
I found the answer to my own problem, but I am posting what solved the problem just in case someone happens to run into the same thing and finds this in the archives somehow.


This is what worked in my Visual Basic Application:

pDoc.[Print] txtPrinterName, txtFirst, txtLast, chkNotes, chkAttributes, chkForm, chkAnnotations

But, this does not work in Visual Basic for Applications (which is what Excel uses). The code in Visual Basic for Applications is:

something = pDoc.[Print]("", txtFirst, txtLast, chkNotes, chkAttributes, chkForm, chkAnnotations)

There is no good reason at all for this code. The Print method in the automation interface does not return anything. I don't know why the parenthese around the parameters are needed either. All I know, is that when I call the method this way, it works, and when I try and call it any other way, I get errors.

I am happy now though, because the problem is solved!

June 6th, 2000, 08:22 AM
It's because you're using the retuirn value in the Excel version. If you had done this in the VB example, you'de also need the brackets there as well. Excel uses the samne version of the VBA engine as VB, so the rules are the same. Hope thjis explains why the fix worked!