Creating a new pdf document using AcroEXch in VBScript - excel

I am looking to automate the conversion of an excel sheet into a pdf document (I do not want to manually print the report generated in excel as a pdf document every morning). For now, I would like to create a button in excel that will run the macro to automatically generate the pdf document, but this button will eventually not be used.
Im also new to VB, but have read up on the AcroEXch SDK. Seems like I should be using AcroEXch.PDDoc.Create, but this is not quite right (because I cannot specify an input file to be printed/created as a new pdf document).
Any ideas on how I can create a brand new pdf file? Thanks in advance.

I think i found the answer. Here is one solution someone at work suggested (if anyone finds it useful, then great).
There is no available method in the AcroEXch class (or set of methods that I know of) to convert a non-pdf file to a pdf file. Instead, you have to use the pdf Distiller to first convert the file to postscript and then you can write to pdf, using the PDFDistiller class. Here's a snippet of the code:
'1. open excel being converted to pdf:
xlReport.activate
xlReport.range("a1").select
dim PdfFilePath
PdfFilePath = ""
dim PsFilePath
PsFilePath = ""
'2. Print Excel file to postscript file
xlBook.activesheet.PrintOut , , 1, , "Adobe PDF on Ne01:" ,TRUE, , PsFilePath
Dim oDistiller
Set oDistiller = CreateObject("PDFDistiller.PDFDistiller.1")
oDistiller.FileToPDF sPsFilePath, sPdfFilePath, ""
' Close Excel - do not save.
'COMMENTED OUT BELOW 3 LINES FOR DEBUG
xlApp.displayalerts=false
xlApp.quit
set xlApp=nothing

I don't know exactly what your circumstance is and what tools you have access to, but reading your description, it sounds like you simply want to have an Excel file converted for you with a click.
It would be helpful if you had posted whether you have Adobo Acrobat Professional, latest version of Excel, or other converters that are available on the market.
If you have Acrobat Pro installed, your office apps (word, excel, outlook, etc) should already have a "Convert to PDF" button in the toolbars, in combination with Excel command line argument it shouldn't be too hard to cook up a Windows Scheduled Task that periodically convert excel files for you.

Have you considered CuteFTP or PDFCreator, both are free. I have sucessfully used PDFCreator with VBA and I have heard that CuteFTP is good.

Related

Create PDF bookmarks Within Excel Workbook

I'm attempting to build a monthly process that converts an excel file to a PDF with bookmarks for each respective sheet. I'm not seeing a method to successfully create PDF bookmarks from within the Excel workbook. Can this be accomplished without third-party software?
What I've tried:
Using Header 1 for a cell as well as an entire row.
Putting Excel Book Mark within the file using a hyperlink reference.
Adding named range.
OneDrive flow Convert File
Adding a Header.
Reviewed some VBA Ref libraries hoping to find an object.bookmark type approach.
Unfortunately, all attempts have resulted in a PDF file with no bookmarks.
Is there a method to create PDF Bookmarks from Excel? Possibly a VBA ref library that I am unaware of or some front-end trick? Unfortunately, I'm stuck working only with Microsoft tools. Adobe's Excel Add-On does exactly what I'm trying to achieve.

Can VBA open a document embedded in an Excel workbook

If I want to open a .oft document from Excel with VBA, I normally indicate the folder path to the .oft document in VBA.
Is it possible to attach/emmbed this .oft in the Excel file and indicate VBA to open it from the Excel file instead of indicating a folder path??
Thanks!
Here's a code sample for VB.NET from Word to give you an idea of the code constructs you need to use. Note that the Excel VBA model and Word VBA model differ and sometimes use different function/method names (I don't know for sure but this sometimes happens). Just search the guides at Microsoft.
For Each shp As InlineShape In wordDoc.Content.InlineShapes
If shp.Type = WdInlineShapeType.wdInlineShapeEmbeddedOLEObject Then
If shp.OLEFormat.ProgID.Contains("Word") Then
shp.open() ' Open the embedded Word document
end if
end if
next

How to Modify an excel document, save as pdf and print it with Python

I need your help please, I want to automize my everyday tasks with python code. I need to open an existing excel document, modify some information in it(ex: date) then save it as pdf and print it.
Is it possible to do all these via python?
I have tried to do this with openpyxl, I can open and modify the sheets, but' I can't save as pdf only one sheet of the workbook and print it then.
Try using xlwings, it allows you to use more or less any Excel feature because it's actually opening the file and working on it (you can decide if that's done in the background or you can actually see it).
Why you need to use Python?
I think easiest way is write macro in VBA excel (which can updating values in your sheet) and than print it out as PDF or .

Convert Excel with internal links to pdf

I am trying to convert an excel with internal links(i.e. links to different places within that same excel) to a pdf. I have gone through the several posts available online in this regard and couldn't seem to find any proper solution for such a conversion. The solutions provided mostly works for the external hyperlinks and not the internal one's. Is it even possible to do so? Is there any software that might be able to achieve this functionality?
Basically, I am looking to migrate whole of the excel workbook to one single pdf such that every link between different worksheets in that workbook still works. For example, if I have provided a link in worksheet one that points to a named section in worksheet two, I would like this relation to be maintained within pdf as well. So, in the resulting pdf when I click on the link, it should take me to that named section location in the pdf.
Solution to keep internal and external links that works:
Install Office 2013/2016
Install Adobe Acrobat PRO 11 (for Office 2013) or Adobe Acrobat DC (for Office 2016)
Open Excel file and use "Save as Adobe PDF" entry from the File menu. Screenshot below. This pops up another dialog where you select sheets for saving.
Main idea is to have Adobe Add-in active inside the Office ribbon and File dialog.
Works like a charm! Finally!

Conversion of Excel into .pdf while using 'IncludeDocProperties' field

I use the following code in MATLAB to convert an Excel worksheet into PDF, but I am getting the info (name) of the Excel file at the top of the PDF.
How can I get rid of it?
I know there is an optional field IncludeDocProperties, but I am not sure how to use it?
hExcel = actxserver('Excel.Application');
hWorkbook = hExcel.Workbooks.Open(sprintf('%s',excel_filepath));
hWorksheet = hWorkbook.Sheets.Item(1);
hWorksheet.ExportAsFixedFormat('xlTypePDF',pdf_filepath);
hWorkbook.Close;
hExcel.Quit;
hExcel.delete;
As far as I know, convert to pdf by ExportAsFixedFormat method will give you a pdf file that looks exactly like what you get when you print out the excel file.
So, the info (name) that you mentioned is not created by Matlab, but by Excel. You have to open the file in Excel, and check if the Header/Footer is turned off or not. If you have Header/Footer turned on for the file, then the pdf exported through Matlab will also have that info (maybe file name, or page number, or author name etc.).

Resources