CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Strange keyword problem with Excel macro

    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!


  2. #2
    Join Date
    Aug 1999
    Location
    CA
    Posts
    2

    Re: Strange keyword problem with Excel macro

    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!


  3. #3
    Guest

    Re: Strange keyword problem with Excel macro

    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!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured