From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do you save an Excel file as a PDF?

Solved!
Go to solution

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

0 Kudos
Message 1 of 19
(7,636 Views)

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.

Lewis Gear CLA
LabVIEW UAV

0 Kudos
Message 2 of 19
(7,624 Views)

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

 

0 Kudos
Message 3 of 19
(7,619 Views)

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.)

Message 4 of 19
(7,605 Views)

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? Smiley Tongue

Lewis Gear CLA
LabVIEW UAV

0 Kudos
Message 5 of 19
(7,598 Views)

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

 

0 Kudos
Message 6 of 19
(7,597 Views)
Solution
Accepted by topic author wd8ivl

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.

Message 7 of 19
(7,595 Views)

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

0 Kudos
Message 8 of 19
(7,582 Views)

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

Message 9 of 19
(7,561 Views)

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

0 Kudos
Message 10 of 19
(7,532 Views)