VBA code - print to pdf and auto save pdf file (File Name To Equal Cell Value)

Donbozone

New Member
Joined
Mar 28, 2020
Messages
37
Office Version
  1. 365
Platform
  1. Windows
Hello to everyone.

I would appreciate if someone can help.

Here is what I have and what I need:

  • I have a source sheet "zaposleni" (it is in Serbian, don't pay attention) and a template sheet called "potvrda PPP-PO"
  • I have a simple VBA code which takes one information from table source and copy it in my template sheet (based on that information other cells in my template are auto-filled with formulas) and after that it starts printing one by one:
Here it is:​
Sub PrintAll()​
Dim i As Long, LastRow As Long​
LastRow = Worksheets("zaposleni").Range("B1000").End(xlUp).Row​
With Worksheets("potvrda PPP-PO")​
For i = 2 To LastRow​
.Range("C14").Value = Worksheets("zaposleni").Range("B" & i).Value​
.Range("Print_Me").PrintOut​
Next i​
If .FilterMode Then .ShowAllData​
End With​
End Sub​

  • This is ok if I want to save one by one manually or merge all in one pdf file, but what I need is the option of auto saving of each file as per specified name.
  • As the path to the folder is required it would be also nice to add browser window (to avoid fixing the path in the code) so I could chose the folder in which my pdf files will be stored.
  • I would add file names in my source table, sheet "zaposleni" in first empty column which is column "E"

This is how the code supposed to work:

  • Start code
  • Browser window opens and ask me where I want to save my pdf files
  • I'm choosing existing or creating a new folder
  • code takes first value from source table (zaposleni B2) and paste in my template sheet
  • code prints template to pdf and takes the name from the same row in source table (my table has headers, so it would be E2) and saves the pdf file under that name
  • operation repeats with row 3 and so on to the last non-empty row in column B of my source table

Hope I was clear and hope it is feasible :)

Thanks
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

jyothisurya111

New Member
Joined
Feb 18, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi Amazing people ,

Can some one help me out with the below request please this is also related to updating the data and saving them as pdf

 

Watch MrExcel Video

Forum statistics

Threads
1,127,405
Messages
5,624,574
Members
416,036
Latest member
eloisa manzanarez

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top