10-01-2012 10:09 AM
Hello list,
Attached is my VI for saving an Excel file as a PDF.
If I execute the VI, it saves a PDF file (probably because I am saving it with a PDF extension).
When I try to open the file in Acrobat, I get the error that it is an unsupported file type.
I'm using "17" as "FileFormat" (I found that online and it's supposed to work for Word, so I thought it would work in Excel).
If I change the "FileFormat" to "56" I can open the saved file back up in Excel and then save it as a PDF using the pulldown menu and it opens fine in Acrobat, so I'm guessing that "17" isn't correct.
Does anyone know the correct value for "FileFormat", or am I doing something else wrong.
Thanks,
Mike
Using LV 2011 in Windows 7 & Excel 2010
Solved! Go to Solution.
10-01-2012 02:24 PM
I'm afraid I don't know the answer to your question but thought you may like to know you can get a PDF Generator for LabVIEW.
If you are using PDF it could be useful.
10-01-2012 02:39 PM
Lewis,
Thanks for the reply.
I've seen a few of those addons, but since I'm already building my report from an Excel template, I'd just like to save it as a PDF since Excel has it built in.
Just have to figure out the correct codes to do it.
Mike
10-01-2012 03:03 PM
Are you sure you want to do a "SAVEAS" to create the PDF? What version of MS Office are you using?
One of the best ways to figure out how to do something with ActiveX in Excel is to first do it in Excel by recording a Macro. See what code Excel generates, then try to model that in LabVIEW.
I don't see .pdf as an option you can save Excel as a filetype to (Excel 2007). But when I go to the Excel 2007 button, Save As, then PDF or XPS while recording a macro, I get this code.
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "C:\Documents and Settings\CurrentUser\Desktop\FILENAME.pdf", Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=True
This shows me you should be usingthe ExportAsFixedFormat method on the worksheet as opposed to trying to use the SaveAs method on the workbook. (But the workbook object as that same method as well.)
10-01-2012 03:26 PM
If you can't find the documentation for it, it might be quicker to brute force it and start trying numbers. There isn't that many file formats right?
10-01-2012 03:28 PM
Thanks for the reply,
It is a "Save As" option in 2010 & Windows 7.
Thanks for the suggestion. I tried recording the macro and it tells me the fileType is "xlTypePDF" I tried to pass this into workbook activex and got an error when I ran it.
From experimentation I think I need a number there, because if I put "56" there, it will create an xls file.
So I have to find out what number corrisponds to "xlTypePDF" in Excel 2010.
Mike
10-01-2012 03:30 PM - edited 10-01-2012 03:32 PM
http://www.lmgtfy.com/?q=xlTypePDF+in+Excel+2010
More specifically, http://code.msdn.microsoft.com/office/Excel-2010-Export-Data-to-07bb5550
Search Excel help for xlTypePDF and you will see the number is 0.
10-01-2012 05:49 PM
Ravens Fan,
Sorry, but I didn't get that far before leaving the office today, and don't have Windows 7/Excel 2010 at home.
I'll try the "0" first thing in the morning.
Mike
10-02-2012 06:54 AM
Ravens Fan,
Thanks! I have it working.
I was using the ActiveX method "SaveAs" and setting the "Type" to "0", but that didn't work. It returned an error and did not create a pdf file.
I changed the ActiveX method to "ExportAsFileType" and set "Type" to "0" and that worked.
Thanks again,
Mike
10-02-2012 10:21 AM
Mike,
My place of business uses Office products A LOT, so I tend to write things using VBA first, get it working the way I like it, then turn to Labview and use ActiveX. I've also used the Excel Run Macro.vi if I have a templete that can't be overwritten or there is specific code that can't be transferred over.
Eric