Saving file when path is unknown

V

vrzimmerm

I am writing a macro utility that will be used on several different
PC's. One step in the macro saves a file using the path of the
currently opened file (where the macro resides). This step works
for my PC since the macro identifies my specific path. I need for
this macro to work when the path of the currently open file is
unknown. How would I do this?

Thanks.
 
J

Joel

The code below will get the users default path by looking at the environment
variable

Sub test()

Dim EnvString, Indx, Msg, PathLen ' Declare variables.
Indx = 1 ' Initialize index to 1.
Do
EnvString = Environ(Indx) ' Get environment
' variable.
If Left(EnvString, 12) = "USERPROFILE=" Then
DefaultPath = Mid(EnvString, InStr(EnvString, "=") + 1)
Exit Do
Else
Indx = Indx + 1 ' Not PATH entry,
End If ' so increment.
Loop Until EnvString = ""
If Len(DefaultPath) > 0 Then
MsgBox "User Default Path = " & DefaultPath
Else
MsgBox "No Default Path Exists"
End If
End Sub
 
V

vrzimmerm

I am writing a macro utility that will be used on several different
PC's. One step in the macro saves a file using the path of the
currently opened file (where the macro resides). This step works
for my PC since the macro identifies my specific path. I need for
this macro to work when the path of the currently open file is
unknown. How would I do this?

Thanks.

I've tried the following coding as I want to save the file under a new
name (tempfile) , but it keeps giving me an error

ActiveWorkbook.SaveAs Filename:= ActiveWorkbook.Path & "\" &
tempfile.xls" _
, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Whay doesn't this work?
 
J

Joel

the filename need to be in double quotes

ActiveWorkbook.SaveAs Filename:= _
ActiveWorkbook.Path & "\" & "tempfile.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
 
V

vrzimmerm

the filename need to be in double quotes

ActiveWorkbook.SaveAs Filename:= _
ActiveWorkbook.Path & "\" & "tempfile.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Perfect! Many thanks.
 

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

Top