Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Saving file when path is unknown

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vrzimmerm@hotmail.com - 24 Sep 2007 12:28 GMT
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.
Smallweed - 24 Sep 2007 12:42 GMT
Have you tried ActiveWorkbook.Path & "\" & ActiveWorkbook.Name

> 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
[quoted text clipped - 4 lines]
>
> Thanks.
Joel - 24 Sep 2007 12:44 GMT
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

> 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
[quoted text clipped - 4 lines]
>
> Thanks.
vrzimmerm@hotmail.com - 24 Sep 2007 13:33 GMT
On Sep 24, 7:28 am, vrzimm...@hotmail.com wrote:
> 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
[quoted text clipped - 4 lines]
>
> 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?
Joel - 24 Sep 2007 13:48 GMT
the filename need to be in double quotes

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

> On Sep 24, 7:28 am, vrzimm...@hotmail.com wrote:
> > I am writing a macro utility that will be used on several different
[quoted text clipped - 15 lines]
>
> Whay doesn't this work?
vrzimmerm@hotmail.com - 24 Sep 2007 14:13 GMT
> the filename need to be in double quotes
>
[quoted text clipped - 23 lines]
>
> > Whay doesn't this work?

Perfect!    Many thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.