Excel Automation Incomplete
Saint-Sage
Member Posts: 92
Hello All,
I am writing a codeunit to export a table to file.
What I currently am running into is that it will create the Excel file, and if I open it from a current running version of Excel it seems to do fine. However, if I double click on the created file then it will launch Excel, but then Excel hangs and has to be shut down, and restarted.
I am thinking that it is missing some piece of data that needs to be initialized. I am also having a problem in that the codeunit only runs every other time. I thought the ISCLEAR code would account for this. But every 1st, 3rd, 5th time I run it I get You must declare automation variable etc...
Any help on either problem would be greatly appriciated, thanks!
Here is the code...
IF ISCLEAR(Appzimus) THEN BEGIN
CREATE(Appzimus);
END ELSE BEGIN
CLEAR(Appzimus);
END;
IF ISCLEAR(AppWKbooks) THEN BEGIN
CREATE(AppWKbooks);
END ELSE BEGIN
CLEAR(AppWKbooks);
END;
IF ISCLEAR(AppWKbook) THEN BEGIN
CREATE(AppWKbook);
END ELSE BEGIN
CLEAR(AppWKbook);
END;
IF ISCLEAR(AppWksheet) THEN BEGIN
CREATE(AppWksheet);
END ELSE BEGIN
CLEAR(AppWksheet);
END;
i := 1;
Appzimus.Visible(FALSE);
Appzimus.ScreenUpdating(FALSE);
Appzimus.SheetsInNewWorkbook := 1;
AppWKbooks := Appzimus.Workbooks.Add;
AppWKbook := Appzimus.ActiveWorkbook;
AppWksheet := AppWKbook.ActiveSheet;
AppWksheet.Name := 'FOAMEX POs - ' + FORMAT(TODAY);
PurchaseLine.RESET;
PurchaseLine.SETRANGE("Buy-from Vendor No.", 'FOAMEX');
PurchaseLine.SETRANGE("Order Date", 101906D);
IF PurchaseLine.FIND('-') THEN BEGIN
REPEAT
AppWksheet.Range('A'+FORMAT(i)).Value:=PurchaseLine."Document No.";
AppWksheet.Range('B'+FORMAT(i)).Value:=PurchaseLine."Line No.";
AppWksheet.Range('C'+FORMAT(i)).Value:=PurchaseLine."Buy-from Vendor No.";
AppWksheet.Range('D'+FORMAT(i)).Value:=PurchaseLine.Type::Item;
AppWksheet.Range('E'+FORMAT(i)).Value:=PurchaseLine."No.";
AppWksheet.Range('F'+FORMAT(i)).Value:=PurchaseLine.Description;
AppWksheet.Range('G'+FORMAT(i)).Value:=PurchaseLine.Quantity;
AppWksheet.Range('H'+FORMAT(i)).Value:=PurchaseLine."Style No.";
AppWksheet.Range('I'+FORMAT(i)).Value:=PurchaseLine."Piece Code";
AppWksheet.Range('J'+FORMAT(i)).Value:=PurchaseLine."Warranty Date";
i += 1;
UNTIL PurchaseLine.NEXT = 0;
END;
AppWKbook.SaveAs('C:\FOAMEXPO.xls');
CLEAR(Appzimus);
I am writing a codeunit to export a table to file.
What I currently am running into is that it will create the Excel file, and if I open it from a current running version of Excel it seems to do fine. However, if I double click on the created file then it will launch Excel, but then Excel hangs and has to be shut down, and restarted.
I am thinking that it is missing some piece of data that needs to be initialized. I am also having a problem in that the codeunit only runs every other time. I thought the ISCLEAR code would account for this. But every 1st, 3rd, 5th time I run it I get You must declare automation variable etc...
Any help on either problem would be greatly appriciated, thanks!
Here is the code...
IF ISCLEAR(Appzimus) THEN BEGIN
CREATE(Appzimus);
END ELSE BEGIN
CLEAR(Appzimus);
END;
IF ISCLEAR(AppWKbooks) THEN BEGIN
CREATE(AppWKbooks);
END ELSE BEGIN
CLEAR(AppWKbooks);
END;
IF ISCLEAR(AppWKbook) THEN BEGIN
CREATE(AppWKbook);
END ELSE BEGIN
CLEAR(AppWKbook);
END;
IF ISCLEAR(AppWksheet) THEN BEGIN
CREATE(AppWksheet);
END ELSE BEGIN
CLEAR(AppWksheet);
END;
i := 1;
Appzimus.Visible(FALSE);
Appzimus.ScreenUpdating(FALSE);
Appzimus.SheetsInNewWorkbook := 1;
AppWKbooks := Appzimus.Workbooks.Add;
AppWKbook := Appzimus.ActiveWorkbook;
AppWksheet := AppWKbook.ActiveSheet;
AppWksheet.Name := 'FOAMEX POs - ' + FORMAT(TODAY);
PurchaseLine.RESET;
PurchaseLine.SETRANGE("Buy-from Vendor No.", 'FOAMEX');
PurchaseLine.SETRANGE("Order Date", 101906D);
IF PurchaseLine.FIND('-') THEN BEGIN
REPEAT
AppWksheet.Range('A'+FORMAT(i)).Value:=PurchaseLine."Document No.";
AppWksheet.Range('B'+FORMAT(i)).Value:=PurchaseLine."Line No.";
AppWksheet.Range('C'+FORMAT(i)).Value:=PurchaseLine."Buy-from Vendor No.";
AppWksheet.Range('D'+FORMAT(i)).Value:=PurchaseLine.Type::Item;
AppWksheet.Range('E'+FORMAT(i)).Value:=PurchaseLine."No.";
AppWksheet.Range('F'+FORMAT(i)).Value:=PurchaseLine.Description;
AppWksheet.Range('G'+FORMAT(i)).Value:=PurchaseLine.Quantity;
AppWksheet.Range('H'+FORMAT(i)).Value:=PurchaseLine."Style No.";
AppWksheet.Range('I'+FORMAT(i)).Value:=PurchaseLine."Piece Code";
AppWksheet.Range('J'+FORMAT(i)).Value:=PurchaseLine."Warranty Date";
i += 1;
UNTIL PurchaseLine.NEXT = 0;
END;
AppWKbook.SaveAs('C:\FOAMEXPO.xls');
CLEAR(Appzimus);
No one loves you like the one who created you...
0
Comments
-
I don't know the answer to your problem but perhaps these can help
From Downloads
http://www.mibuso.com/dlinfo.asp?FileID=583
http://www.mibuso.com/dlinfo.asp?FileID=207
http://www.mibuso.com/dlinfo.asp?FileID=350
From Tips N tricks
http://www.mibuso.com/forum/viewtopic.php?t=9270 -
Thanks for the links Savatage, though they didn't help unfortunately, there were some slick ways of doing things and were worth reading.
When I downloaded and installed FILEID=583, it did exactly the same thing mine did. The Excel file created will open and can be viewed if you open Excel first, then do a File->Open. However, if you just double click on the file sitting in a directory, Excel hangs when opening, and you never see the data.
Some of those code examples did less setup than I did, so I am not sure if the authors actually checked the validity of the file by opening it from explorer.
If any automation experts have a suggestion I would be greatful!
Thanks!
No one loves you like the one who created you...0 -
Problem is there:
IF ISCLEAR(Appzimus) THEN BEGIN CREATE(Appzimus); END ELSE BEGIN CLEAR(Appzimus); END;
What does this code mean? In case, that Appzimus is inicialized, it will clear it (and it will be not inicialized, the automation will be released), if it is not inicialized, it will create the automation. Correct isIF ISCLEAR(Appzimus) THEN BEGIN CREATE(Appzimus); END;
orIF not ISCLEAR(Appzimus) THEN BEGIN CLEAR(Appzimus); END; CREATE(Appzimus);
Same for other automation variables...0 -
Thanks kine!
No one loves you like the one who created you...0 -
-
Ok. I have uninstalled and re-installed Microsoft Office XP 2003. I have run "C:\Program Files\Microsoft Office\OFFICE11\Excel.exe" /Regserver to try an make sure the Automations are registered. If I pull up Automation types and create the variables, then the Excel 11.0.Application, Worksheet, etc all show up. However, when I go to run the code, it tells me
could not create an instance of the OLE control or Automation server identified by GUID {blah blah blah}...
I have never had a re-occuring/disappearing magic bug like this before. Does anyone have any experience? Thanks
No one loves you like the one who created you...0 -
I think I may have found the problem, I am currently backing some stuff up and am gonna try some things.
My client originally had a NAV 3.10a database on top of SQL Server. The client was upgraded sometime back to 3.7a. When I first received the database, I opened it in 4.0 SP1 and allowed it to convert the older version.
I am thinking that with the 3.1 database and the 3.7/4.0 client there was some mixing of communication libraries on the installations.
I am going to work on it now and I will post the results in a little while.
Everyone have a good night/day depending on your GPS Location.
No one loves you like the one who created you...0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
