Excel Automation: SaveAsPdf

_Midnight_
Member Posts: 15
Hi guys!
Hope somebody can help me with this...
I use excel Automation-obj to fill several data into a sheet. This happens not visible to the user,
in background. After data are filled in, I want to save the sheet as PDF, and then open it.
I used the vba-editor to get an idea of how to call the right function.
Result is: Excel uses "ExportAsFixedFormat"
I've tried several parameters, but the command always fails with error -2147352567.
Searching for description at google and microsoft didn't helped a lot.
Does anybody got a hint?
Or does someone already have a solution for saving excel as PDF from C/AL?
Appreciate every help!
Hope somebody can help me with this...
I use excel Automation-obj to fill several data into a sheet. This happens not visible to the user,
in background. After data are filled in, I want to save the sheet as PDF, and then open it.
I used the vba-editor to get an idea of how to call the right function.
Result is: Excel uses "ExportAsFixedFormat"
I've tried several parameters, but the command always fails with error -2147352567.
Searching for description at google and microsoft didn't helped a lot.
Does anybody got a hint?
Or does someone already have a solution for saving excel as PDF from C/AL?
Appreciate every help!
0
Comments
-
....additional Info:
When I remove the Export-Command from C/AL (or comment-out), and trigger it as macro from the open Excel, it works perfect.0 -
Could you show the code + the macro code?0
-
Code in nav as follows....
xlWbook := xlApp.Workbooks._Open(gTemplateFile); //Specific data xlSheet := xlApp.Sheets.Item(1); xlSheet.Range('C3').Value := gFType; xlSheet.Range('C4').Value := '596'; xlSheet.Range('C5').Value := '896'; xlApp.ScreenUpdating(FALSE); xlApp.Visible := FALSE; //Change to Printsheet, Export as PDF xlSheet := xlApp.Sheets.Item(6); xlSheet.ExportAsFixedFormat(0,'C:\exports\dataRange.pdf',0,TRUE,FALSE,'','',TRUE); //<--- Error thrown //Close WB xlWbook.close; xlApp.Quit;
And the macro code stays quite the same:ActiveSheet.ExportAsFixedFormat xlTypePDF, "C:\exports\dataRange.pdf", xlQualityStandard, TRUE, FALSE, , , TRUE
0 -
How do you call the macro?
Im using Excel a lot too. Maybe try to replace the explicit parameters with vars.
So
''
becomes
LtStringEmty := '';
0
becomes
LiZero := 0;
TRUE
becomes
LbTRUE := true;
etc.
xlSheet.ExportAsFixedFormat(LiZero ,'C:\exports\dataRange.pdf',LiZero,LbTRUE,LbFALSE,LtZero,LtStringEmty,LbTRUE);
ps.
Whats helps too is not use integers or strings but use variants vars like LvTRUE := true;0 -
I tried what you have suggested, but it didn't helped.
I still get the exception....
For now, I will call a macro with the export command.
But I don't like doing it that way at all, cause I have to save my template with macros,
and furthermore, edit the security settings of excel, to permit execution of it.
The way I call the macro:xlApp.Run('macroName','param1','param1');
thanks again0 -
Try this one:
xlSheet.ExportAsFixedFormat(0,'C:\exports\dataRange.pdf');
regards,
winfy0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions