Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Excel automation 101
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00543842
Message ID:
00544509
Views:
11
Hi Andrew,

I'm still getting this program error that I can't make head or tail of. In order to test it, I created the following little prg:
oEx = CREATEOBJECT("Excel.Application")
* -- The file I'm working with
oEx.Workbooks.Open("c:\My Documents\hairtrek\hairtrek.xls")  && it exists

* -- I tried one of the following and then the other, both and then neither - 
* -- unclear on the concept, perhaps??
#INCLUDE xl97cons.h  && found it - it's in the path
* #DEFINE xlDown -4121 && this was in the code
oEx.Rows("5:5").Select  && works

* -- Tried all of the following in succession, all of which stuffed up, with
* -- runtime error described below

oEx.Sheets.Selection.Insert(0xFFFFEFE7) && with/without #INCLUDE and/or #DEFINE
* oEx.Sheets.Selection.Insert(-4121) && with #INCLUDE and/or #DEFINE
* oEx.Sheets.Selection.Insert("-4121")  && with #INCLUDE and/or #DEFINE
* oEx.Sheets.Selection.Insert("0xFFFFEFE7")

* -- the rest works fine, as a peek into the task manager shows
oEx.Workbooks.Close
release oEx
The error is the following:
OLE error code 0x80020006: Unknown name

Any idea why this is happening, what I am doing wrong?
Thanks so much for your patience with my struggles with this - BTW, I have ordered "Office Automation with Visual FoxPro" from Amazon today (came to $61.93 with non-priority shipping!!), which will hopefully put an end to some of these newbie questions.

Kindest regards,
Robin

>
>  * Insert a row
>  .Rows("5:5").Select                        && works
>  .Sheets.Selection.Insert <b>Shift:=xlDown</b>     && generates a compile error
>ENDWITH
>
>
>The problem is that you're using Excel Syntax - in particular:
>
  • you're trying to name parameters.
    >
  • you're not using parens in your method call
    >
  • you're using an excel type library constant name rather than its value
    >
    >To solve this, look up the vba help file for excel to find out where the shift parameter occurs in the Insert method's parameter list (it happens to be the first parameter in this case) and what the value for xlDown is (it's -4121 or 0xFFFFEFE7). This means you call should be:
    >
    >  .Sheets.Selection.Insert<b>(0xFFFFEFE7)</b>     && should no longer generate a compile error
    >
    >
    >You can also look up the parameters and constant values using the VBA object browser. Bring up the VBA IDE in excel (ALT+F11) and then the object browser (F2). Enter the method, property or constant name you're looking for in the second drop-down in the right-hand pane and it will give you all the details in the lists below.
    >
    >Finally, I'd highly recommend Della Martin and Tamar Granor's book available from Hentzenwerke - something like Microsoft Office Automation with Visual Foxpro. I got Amazon to ship mine out here (I don't think Whil ships direct here to Australia).
    >
    >Cheers,
    >
    >Andrew
  • Previous
    Next
    Reply
    Map
    View

    Click here to load this message in the networking platform