Could not invoke member ActiveWorkbook

TimoBoTimoBo Member Posts: 31
Hi,

I have an Excel 2003 file with 3 worksheets. One worksheet contains a pivot table. When I try to open the file from Navision, I get the following error:

Could not invoke the member ActiveWorkbook.
Create(Excel);
Excel.Workbooks.Open(FileName);
ExcelWorkbook := Excel.ActiveWorkbook;

The same function works fine with Excel files without pivot table.
Does anybody know more about this problem?

Comments

  • [TweaK][TweaK] Member Posts: 14
    You get that error because you open the workbook but it is not active, it's just open.
    By first creating your autExcel object and then just adding the workbook straight from the file this error SHOULD not occur.
    So try the following:

    CREATE(autExcel);
    autWorkBook.Close; //=> Always close any active open workbook
    autWorkBook := autApplic.Workbooks.Add(ptxtFileName);
    autWorkSheet := autWorkBook.ActiveSheet;
    FYI: First Close any open workbook!

    I wish you the best!
  • Theo_van_de_VenTheo_van_de_Ven Member Posts: 22
    Hi Timobo,

    Today I encountered exactly the same problem. First thought that it was caused by a corrupted installation somehow but that was not the case. The problem is reproducable on other PC's of our company too. Another reason I thought of was the 64-bit OS (Windows 7). Tried it on Windows Server 2003 64 bit too. Everywhere the same error kept popping up.

    When I entered the debugger and stepped through the code the code ran without any problem. But running it without debugger did not. Been almost busy whole day to solve this, but the good news is ... I found a solution/work around! :D

    What I did was simply adding a SLEEP(100) statement between the last two lines.

    Excel.Workbooks.Open(FileName);
    SLEEP(100)
    ExcelWorkbook := Excel.ActiveWorkbook;

    For me it works. Apperently the OS must be given a short time to execute some background processing.
    If somebody has a better solution it would be greatly appreciated when it was shared here.
    Theo van de Ven
    Technical Consultant | System Administrator

    Rainbow Crossmedia BV
    Bosmanskamp 63
    4191MT Geldermalsen
Sign In or Register to comment.