Saving with VBA to Public Documents

annapodzharova

New member
Hello,

I’m trying to save with VBA to the Public Documents folder, but the file saves in My Documents folder. I’m using the function “SaveSecureWorkbookToFile” and the path to Public Documents:“C:\Users\Public\Documents” , but each time it ends up saving in My documents. Could you please suggest which path I need to use to save in Public Documents?
Thanks.
 
The issue stems from the need to provide a complete and correct absolute path when using SaveSecureWorkbookToFile. If a full path is not specified, the file defaults to being saved in the “My Documents” folder.

You can modify your VBA code as follows to ensure that the file saves in the Public Documents folder:
Code:
Dim publicDocsPath As String
publicDocsPath = Environ("PUBLIC") & "\Documents\"
SaveSecureWorkbookToFile publicDocsPath & "myfile.xlsc"
This will set the path to the Public Documents folder dynamically using the Environ("PUBLIC") function, which retrieves the correct path to the Public directory, and then appends \Documents\ to ensure it points to the right folder.
 
Back
Top