Pdf- Xps-add-in Für Microsoft Office 2007

0 views
Skip to first unread message

Janne Evers

unread,
Aug 3, 2024, 1:56:06 PM8/3/24
to hyarenasa

Hey, Scripting Guy! There are some things I really enjoy about working for a small company. I am the only IT person, and as a result I get a chance to do everything. I work with the Exchange Server. I add users to Active Directory. I handle the backup software, perform database maintenance, update antivirus signature patterns, approve updates for the SUS server, and handle all help desk calls. Actually, the help desk is my office phone. And when I am not busy, I even conduct user training sessions on new products that I deploy such as Office 2010.

If you could pull off some sort of scripting magic, it would make my life significantly better and perhaps save me from the same fate that befell the accountant at work. There are no other jobs in the small town where I live, and with teenagers in school, moving is completely out of the question. Help!

DF, this script is not a life changer, at least not for me. If it solves a problem for you and addresses a major pain point, I am ecstatic. The complete ExportTo-ExcelPDF.ps1 script is shown here. The only thing you will need to change is the path to the Microsoft Excel files.

Unfortunately, Microsoft Word uses the SaveAs method to save a Word document as a PDF file. Microsoft Excel uses a completely different method, the ExportAsFixedFormat method. It is not too bad after you figure out what you need to do. As a matter of a fact, the ExportAsFixedFormat method is much easier to use than the Microsoft Word SaveAs method, which requires passing values by reference.

The ExportAsFixedFormat method needs to be told how to export the workbook, which can be exported as either a PDF file or a Microsoft XPS file. The cool thing about a Microsoft XPS file is that it does not require installing third-party software, so any updates the XPS viewer requires come on patch Tuesday with all the other updates. Therefore, DF, you could use your Windows Server Update Services server to schedule updates for it.

To work with Excel, you first need to create the Excel.Application object. I set the visible property to false to avoid a bunch of spreadsheets popping up and closing. This section of the code is shown here:

I use the foreach statement to loop through the collection of files. Inside the loop, I first create a path to the newly created PDF file. I then open the workbook with a value of 3 which means to update links when opening. I then set the saved property to true, and display a status message. This is shown here:

DF, that is all there is to using Windows PowerShell to save Microsoft Excel workbooks as PDF files. As an added bonus, I also wrote a script to save workbooks as XPS files. Microsoft Excel Week will continue tomorrow when we will talk about removing document information from a Microsoft Excel workbook.

We invite you to follow us on Twitter and Facebook. If you have any questions, send email to us at scri...@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages