Opening files - macro

M

Max2073

Help Needed.

I had developed a macro that was used by myself, however now the macro needs
to be utilised by others.

The marco opens files, that have been exported from the corporate database.
The files are saved automatically to the users C Drive eg. C:\Documents and
Settings\"username – officer logged on"\help.xls

The only difference is the username in the file path.

Is there anyway that I can change the file path to automatically go to the
correct file, without having to create a different macros for each user.

Any help would be greatly appreciated.
 
J

JLatham

Use the Environ("USERPROFILE") function to get the logged on user's path.

You can use code like
MsgBox Environ("USERPROFILE")
to see what it returns on any given machine and adjust your path accordingly.

Code to do the save could be something like this:

Sub TestFileSaveAs()
Dim myPath As String

myPath = Environ("USERPROFILE") & "\test.xls"
Application.DisplayAlerts = False
ThisWorkbook.SaveAs myPath
Application.DisplayAlerts = True
End Sub
 
J

JLatham

Oops, you wanted to OPEN the workbook, not change it's saved location. Same
deal just different command to use the myPath developed:

Workbooks.Open myPath
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Opening Files 1
Opening Files - Marcro 1
Opening Files - Marco 1
Automatically opening file saved to someone "Documents&Sett' direc 2
File Path 2
Path and File 1
File Path 1
File Path 1

Top