location to save pdf

robertvdb

Active Member
Joined
Jan 10, 2021
Messages
327
Office Version
  1. 2016
Platform
  1. Windows
I have a workbook which is being used by different users, but on a central network PC. There is a macro which saves specific Ranges as a PDF.

Depending on which user, the pdf needs to be saved in different directories.

Example: when Bob needs to save a PDF, the location is C:\Documents\BobFiles
for John it will be C:\Documents\JohnFiles

and so on.

Is there any way where John and Bob can indicate their location PRIOR to saving, so that they do not save their files at the wrong place ?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi robertvdb,

maybe use

VBA Code:
"C:\Documents\" & Environ("Username") & "Files"

or

VBA Code:
Environ("USERPROFILE")

which will return "C:\Users\Holger" and could be amended with "Files".

Ciao,
Holger
 
Upvote 0
You could add the following code at beginning of macro:

VBA Code:
Dim saveDir As String
saveDir = InputBox("Enter the location to save the PDF:", "Save Location")

That will prompt user to enter location. You could then use that variable to construct full file path where pdf should be saved.

VBA Code:
Dim pdfFile As String
pdfFile = saveDir & "\" & "MyPDF.pdf"


or something like that..
 
Upvote 0
Thanks cspengel

two remarks:

1) how to select saveDir through a File Dialog box ?
2) I would like to keep the saveDir value throughout the project, so to also use it in other Subs in the project.

Thanks
 
Upvote 0
Hi Robert,

maybe

VBA Code:
Sub MrE_1226506_1700A12()
Dim strPathFolder As String

With Application.FileDialog(msoFileDialogFolderPicker)
  If .Show = -1 Then strPathFolder = .SelectedItems(1)
End With

MsgBox strPathFolder
End Sub

If you want to use the variable elsewhere you could declare strPathFolder as a flobal variable at the top of a standard module like

VBA Code:
Public g_strPathFolder As String
'

Sub MrE_1226506_1700A12()

With Application.FileDialog(msoFileDialogFolderPicker)
  If .Show = -1 Then g_strPathFolder = .SelectedItems(1)
End With

MsgBox g_strPathFolder
End Sub
You should make sure by checking that the variable holds a value before applying it elsewgere.

Holger
 
Upvote 0
Solution
Sorry to keep you waiting, Holger. Your code works fine.

Thanks, Ralph
 
Upvote 0
Hi robert,

thanks for the feedback, glad we could help here.

Holger
 
Upvote 0

Forum statistics

Threads
1,215,711
Messages
6,126,401
Members
449,312
Latest member
sweetfriend9

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
Back
Top