Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone

I have a number of Excel(2010) spreadsheets that reside on a server.
Each of these have the property 'Read-Only' set. This, obviously, disallows the user from saving(overriding) the original copy.

My problem, however, is that I want the users to save a copy to their "My Documents" on drive C:.

I have looked at the Workbook_BeforeSave event but have no idea of how to change the default path.

Could anyone suggest if and how this could be done.

Thanks in advance.

Darrell
Posted

1 solution

The simplest way is to use Environ, ChDrive and ChDir function.

VB
Dim sUserPath As String, sDefaultPath

sDefaultPath = Application.DefaultFilePath
sUserPath = Environ("USERPROFILE") & "My Documents\" 

'first method:
'ChDrive sUserPath
'ChDrir sUserPath

'second method
Application.DefaultFilePath = sUserPath

'your code here

'restore default path
Application.DefaultFilePath = sDefaultPath


How to get MyDocuments folder using other methods? Please, see: Get the Path to My Documents in VBA[^]
 
Share this answer
 
Comments
Darrell de Wet 2-May-14 1:54am    
Thank you very much.
Maciej Los 2-May-14 1:57am    
You're welcome.
Please, accept this answer as a solution (green button) to remove question from unanswered list.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900