Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Saving file when path is unknown

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Saving file when path is unknown

Have you tried ActiveWorkbook.Path & "\" & ActiveWorkbook.Name

" 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
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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Saving file when path is unknown

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


" 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
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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Saving file when path is unknown

On Sep 24, 7:28 am, 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
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?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Saving file when path is unknown

the filename need to be in double quotes

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

" wrote:

On Sep 24, 7:28 am, 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
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?




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Saving file when path is unknown

On Sep 24, 8:48 am, Joel wrote:
the filename need to be in double quotes

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

" wrote:
On Sep 24, 7:28 am, 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
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?


Perfect! Many thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving txt file from excel by specifying path - drop down directory explorer Riggi Excel Programming 3 December 28th 06 01:56 AM
Force Path for File Saving Chris Gorham Excel Programming 1 December 24th 06 10:14 AM
Linked file in same folder but unknown path Christy Excel Programming 6 October 4th 05 06:30 PM
Saving a file to a different path SVTman74 Excel Programming 1 July 26th 05 08:52 PM
Checking if workbook open (where path is unknown) [email protected] Excel Programming 0 September 4th 03 11:13 PM


All times are GMT +1. The time now is 10:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"