![]() invoiceRng.ExportAsFixedFormat _įinally, we use the ExpoortAsFixedFormat method of Range class to print the defined Excel range as PDF. As a result, pdfile contains the fully qualified name of the resultant pdf file. In the above two lines, we first name the file with a timestamp and then add to the path of the main file. pdfile = "invoice" & "_" & Format(Now(), "yyyymmdd_hhmmss") & ".pdf" Since our printing range is fixed, we set the invoice range as Range("A1:L21"). strFile for the fully qualified filename of the resultant PDF. "InvoiceRng as Range" for the range/sheet that we want to save as pdf. Adjust the range and the file path (if you want to) in the code that you want to print. InvoiceRng.ExportAsFixedFormat Type:=xlTypePDF, _Ĭopy the above code in your receipt file by opening the VBA editor ( use Alt+F11). The resultent pdf will be saved where the main file exists. Pdfile = "invoice" & "_" & Format(Now(), "yyyymmdd_hhmmss") & ".pdf" We will adjust the code as per our requirement. To save on this excel range as PDF, we will use the above mentioned generic VBA code of exporting excel sheet to pdf. I want to print/save/export it as a pdf using the button "Create PDF". Here, I have designed this receipt format. If you can just use a button to do this it would be helpful, isn't it? You wouldn't want to do the export excel to pdf over and over again. In that case, you would like to have it automated. Let's say you have to print and send receipts in Excel on a regular basis. Example: Print Excel receipt as a PDF using VBA The rest of the variables can be left as it is. You need to define it.įilename: This is the fully qualified name of pdf. ![]() Range: It can be a fixed range, a dynamic range or a selection. ![]() When your record macro while you export excel to PDF, a similar code will appear. The above code is a generic code to save a fixed range as a PDF document. IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True " C:\Users\file_name", Quality:=xlQualityStandard, _ Range.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ To save a selected range in excel (say a receipt) as PDF in Excel using VBA use below syntax.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |