So the VBA code will be:ĪctiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _įilename:="C:\Users\Public\ExcelDemy\Martin Bookstore.pdf" I will save the PDF with the name “Martin Bookstore.pdf” in path C:\Users\Public\ExcelDemy on my computer. Now we’ll convert the same workbook to another PDF file specifying the name and the path. Here it’s named as Book1.pdf as the name of my workbook was Book1.Įxample 2: Print to PDF in Excel VBA with Name and Path Specified Run this code, and you’ll find a PDF file with the same name as your workbook (Default name when no name is specified) in the same folder with your workbook (Default folder as no path is specified). Let’s write a simple VBA code to convert the worksheet to a PDF document, specifying no name or path.ĪctiveSheet.ExportAsFixedFormat Type:=xlTypePDF Here we have a worksheet with the book records of a bookshop called Marin Bookstore. Let’s explore a few examples of how to print a document to PDF in Excel VBA with the ExportAsFixedFormat method.Įxample 1: Print to PDF in Excel VBA with No Name or Path Specified Print to PDF in Excel VBA with the ExportAsFixedFormat Statement: 5 Examples It converts the worksheets of an Excel workbook as a PDF document and saves it to the specified folder with the specified name. Set it as True to open the document after publishing or set it as False. The starting page number from which your document will start to be saved. Set True to ignore the print areas, or False not to ignore the print areas. Set it as True to include the doc properties, or set it as False not to include the doc properties. Use xlQualityStandard for the standard quality, or xlQualityMinimum for the minimum quality. Enter the full path of the file here if you want to save the file in a different path from the workbook.ĭenotes the quality of the file to be saved. The name of the file that you want to save. Use xlTypePDF for PDF files, or xlTypeXPS for XPS files. It processed these 3 Excel files fairly quick, less than 1 minute.Denotes the type of file you want to save as. This workflow works fine on your workstation, but it will have difficutlies if deployed to the Alteryx Server because we hardcoded the Excel files it process, the workflow may need to be converted to an Analytic Application. We are set, now we run the workflow, it generates 3 PDF files, each one located at the folder where the Excel file is found. Warning: If the workflow is running local on your workstation (laptop or desktop), you can enter any folder and it will work while if you deploy this workflow to the server, the environment to select the files is different, beside, the list of files is "hard coded" into the workflow, so my advice to deploy to the Alteryx Server is to convert this workflow to an Analytic Application. This step is simple, just add the file or files to the input tool.Update the workflow's Text Input with the file or files to process: I am not sure, but the Workflow-macro-vbs will print whatever is defined in the "Print Area" so if your Excel file has many sheets, it will print whatever is defined as Print Area (I haven't test this).We followed Maria's directions to set the "Print Area" on these two sheets.The third Excel file is: "SO FC data sample.xlsx" also located on my D:\Temp\2023-07-July, with 3 sheets: "Sheet1", "Sheet2" and "Sheet3", in this case "Sheet3" is empty, nothing to do with it.Let's allow Maria on this video to explains: How to Set the Print Area in Excel (Step by Step) (Great video by the way) This Sheet contains 17 record, We need to define its print area in Excel. " Sheet2" and " Sheet3" are empty, so nothing to do with them.The second Excel file is: " B2B TackMyOrder Testing.xlsx", this file has 3 worksheets: " Sheet1", " Sheet2" and " Sheet3".The first Excel file is the Sample_File_1.xlsx already shared, nothing to do here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |