Viewed 49k times. Any help would be appreciated. Open ThisWorkbook. Open arrayFilePaths 0 Debug. Open arrayFilePaths arrayIndex Debug. TimWilliams , it is the code for the acrobat api which does all excel vba to combine pdfs. But you say you don't want to use a third-party component. Dont want to use a random plugin though. Add a comment. Active Oldest Votes. Pdf" myCol. I tried this, i get DONE , but where does the final file export too? I checked my path in the array, I dont see my second pdf appended to this file.
Am I missing something else I have to alter? Hey looks like your original code works now.. Show 10 more comments. Close End Sub. The below code i got from stack overflow this will list all sub folders in a folder. Sub FolderNames 'Update Application. ActiveSheet Sheets "Sheet1". Clear xWs. Cells 1, 1. Cells 2, 1. Resize 1, 5. AutoFit Application.
End xlDown. Path, Left SubFolder. Range "A34" UserForm4. Range "A28" UserForm4. Range "A26" UserForm4. Range "A12" UserForm4. Range "A18" End With Application. Community Bot 1 1 1 silver badge. Adavid02 Adavid02 1 1 gold badge 5 5 silver badges 19 19 bronze badges. Add a comment. Active Oldest Votes. Range "I28". Range "I29". Sheets "Form Input Data". Range "I35". Range "I42". GetFile strFilename. Unprotect Sheets "Form Input Data".
Unprotect Sheets "Data Tracker ". Unprotect With Sheet FileDialog msoFileDialogFilePicker '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' With fd 'Use a With Hide 'This is the main UserForm where the data ends up. ProtectedViewWindows 1. Range "A60". Text 'UserForm2. Range "A46" UserForm4. Range "A55" UserForm4. Range "A56" If Sheet8. You have the option of choosing the quality of the resulting PDF file standard or minimum.
More precisely, you can choose 1 of the 2 xlFixedFormatQuality options :. To make this choice, you simply need to set the IncludeDocProperties parameter to True or False as follows:. By using the IgnorePrintAreas parameter of the ExportAsFixedFormat method, you can specify whether Visual Basic for Applications should ignore or not the print areas that have been set for the relevant Excel file. To specify whether the print areas should or shouldn't be ignored, set the IgnorePrintAreas parameter to True or False as follows:.
More precisely:. You specify whether the file is displayed or not by setting the OpenAfterPublish parameter to True or False , as follows:. For purposes of this example, I have prepared a sample Excel workbook. This workbook contains 2 worksheets. Each worksheet includes a table that lists persons and their contact details, along with i their food preferences, and ii their favorite animal and the name of their pet. Therefore, strictly speaking, you can create a very simple macro for purposes of saving an Excel file as a PDF.
As I explain when introducing the Worksheet. ExportAsFixedFormat method above, the reference to the method must be preceded by a variable representing a Worksheet object. ActiveSheet property is used for these purposes. More precisely, ActiveSheet return an object representing the active sheet within the active or specified workbook. The purpose of this method is to save the relevant object a worksheet returned by ActiveSheet in the example above as a PDF file.
Type is the only required parameter of the ExportAsFixedFormat method. Its purpose is to specify the type of file format to which the relevant worksheet should be exported to. You specify the relevant file type by choosing the appropriate value from the XLFixedFormatType enumeration.
However, this doesn't mean that you should be using this macro to convert all of your Excel files to PDF. The reason for this is that, as I show below, the macro literally just saves the active worksheet to a PDF file. Since it doesn't make any adjustment prior to the conversion, the results aren't necessarily the best. The following image shows the resulting PDF file:.
However, there are several things that can be improved. The following are 2 examples:. I show you how to solve several of these issues in the other VBA code examples within this Excel tutorial. Let's start to tackle some of these problems by using the additional arguments of the ExportAsFixedFormat method:.
ExportAsFixedFormat method with its only required parameter Type. Therefore, in this second example, I include most of the parameters that you can use when working with the ExportAsFixedFormat method. These first 2 lines are the whole body of that previous macro. In this particular case, they have the same purpose as that which I explain above.
As I explain above, the previous sample macro simply used the name of the active Excel workbook to name the PDF file that was created after executing the ExportAsFixedFormat method. By using the Filename parameter, you can choose a different filename. In this particular case, the filename that I'm using is quite simple and only includes the actual filename.
Therefore, the PDF file is saved in the default file location. However, as I explain above, you can use this same parameter for purposes of determining the full path of the converted PDF file. IncludeDocProperties can be set to either of the following 2 values :. The purpose of the IgnorePrintAreas parameter of the ExportAsFixedFormat method is to d etermine whether any print areas that are set when publishing should be ignored or not.
Had I omitted any of these parameters, the effect would have been as follows:. You can also set OpenAfterPublish to False. In this case, the published PDF file isn't displayed. However, notice some of the effects of the additional parameters that I included in this second macro:.
Overall, the explanations and examples in the sections above show most of what you need to know about the ExportAsFixedFormat VBA method. You may notice, however, that there are a few things that you can't fix with the ExportAsFixedFormat method alone. This includes, among others, one that I mention above:.
The page layout isn't properly adjusted. Therefore, the resulting PDF file only shows the first 4 columns of the table within the original Excel source file. The last column which corresponds to Favorite Food Ingredient in the example above is missing. There are many ways in which you can use other VBA constructs to create more complex and sophisticated macros to save Excel files as PDF. I show you some of the constructs you can use in the following sections, along with some further examples.
Within Excel, whenever you need to manually adjust the page setup before printing an Excel file or saving it as PDF, you go to the Page Setup dialog box. Whenever you're working with Visual Basic for Applications, you can use the Page Setup object for purposes of modifying any page setup attributes.
The reason for this is that, as explained at the Microsoft Dev Center in the webpage I link to above , the Page Setup object :. As a consequence of this, the list of properties that are members of the Page Setup object is quite extensive. Let's take a look at it:. By my count, the PageSetup object has the 48 properties that I introduce in the table below. The purpose of this table is simply to introduce these properties and their main purpose.
However, I explain some of the properties you may want to explore when working with the ExportAsFixedFormat method below. This third example builds on those 2 examples in particular example 2 above to show how you can improve the results you obtain when carrying out an Excel to PDF conversion using VBA.
Therefore, in this particular section, I only explain line-by-line the first section of the macro. In other words, the With… End With block. The With statement allows you to execute a series of statements on a particular object ActiveSheet. PageSetup in this case without having to repeat the object qualification every single time. In other words, all of the statements within the With… End With block rows 2 to 8 below make reference to the object that appears on the opening statement ActiveSheet.
The object that appears on the opening statement is the page setup description of the active sheet. The object is obtained by using the Worksheet. PageSetup property. In this particular situation, the Worksheet object is the active sheet ActiveSheet.
The PageSetup. CenterHeader property allows you to set what appears in the center section of the page header. You specify the text that you want to appear in this section as a string. You can generally apply the syntax and explanation I provide here for the CenterHeader property to the following roughly equivalent properties:.
You can use the PageSetup. Orientation property for purposes of setting the xlPageOrientation value that specifies the page orientation. The Orientation property can take the following 2 values :.
You generally specify the relevant range using A1-style references and as a string. Under the A1-style cell referencing style, you use letters for column headings and numbers for rows. This range is from cells B5 to F PrintTitleRows property allows you to specify that a particular row or set of rows should be repeated at the top of each page. Generally, you specify the rows to be repeated as a string using A1-style references.
In this particular example, I don't explicitly type A1-style references in the code. Rows 5.
0コメント