I want to create a macro to save as a pdf and have it automatically save it to a specific folder and name it as the value of a cell cell is i3. It is always awesome to see how clean the vba can be if you know what you are doing i usually search for the different components or record bits and try to stitch them together. Im new to using macros, and i havent been able to figure out how to adapt the macros of other questions to suit what i need. Macro to save as pdf with auto filename as cell value i want to create a macro to save as a pdf and have it automatically save it to a specific folder and name it as the value of a cell cell is i3. Hi i recently used the following macro, provided by garys student, to create a pdf from an active sheet, generate a unique filename based on 73779. Saves pdf to a specific location, indicated in cell h1, with an auto filename based on the sheet date within cell i3, formatted as yymmdd. Excel trying to save as pdf using a cell value for both the path and. Save file based on value in cell this macro demonstrates how to take the text from a cell and use that as the file name when the file is saved. Excel trying to save as pdf using a cell value for both the path and the file name microsoftexcel vba microsoftoffice2016. Vba to print sheet to pdf and save using name in cell. If youre creating a macro to save excel files as pdf, and. If that is not possible, id like to reference a cell to use as. Posting your question in threads started by others is a violation of the forum rules and is known as thread hijacking. Cheers luke, if i know the range of cells that from the page, e.
Vba save as pdf with filename as cell value stack overflow. Excel sheet save as pdf in specific folder vba macro youtube. Macro to save as pdf using file name in cell mrexcel. Name command in the file name it works, however when i change it to a range for a cell that is dynamic it no longer works and errors out. The following code saves the selected sheets as a single pdf. I recorded a macro to save my file as pdf and assigned the macro to a button. Select dim filename as string dim chdir as string filename rangea1 chdir c. Solved macro button code, saveas pdf w file name from cell. I want the macro to automatically name the file with the contents of cell z1. Macro to save as pdf with auto filename as cell value.
Dim strfilename as string dim rngrange as range considering sheet1 to be where you need to pick file name set rngrange worksheetssheet1. From a vba perspective, it is the exportasfilxedformat method combined with the type property set to xltypepdf that creates a pdf. Now i would like to change my macro to pause when the file is saving to allow the user to enter a file name. This section contains the base code to save excel as pdf from different objects workbooks, worksheets, ranges and charts. Create pdf file with name from worksheet cells check for existing file, prompt to overwrite or choose different name. K30 is there another line i can put in to make that the active sheet for the save. Select dim filename as string dim chdir as string filename rangea1 chdir. The vba function provides a way of testing any file name your users provide to save the pdf document as. Excel warriors, a cheeky request for a bit of scripting could anyone please provide me with vba code to save the current active sheet as a. Opens outlook and displays email with pdf attached file with date now auto fills recipients, reading from cell c50. Vba to quickly save as pdf document from selected excel. Function validfilenamefilename as string as boolean purpose.