Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default closing a variable file name with macros

I'm using Excel 2003. I have created a separate workbook from a worksheet
and saved it to my hard drive. I am using the current date as part of the
file name so that it changes daily. All this works fine, but I can't close
the file after I save it. This is what I have now:

Dim strappend As String
Dim strpath As String
Dim str3 As String
Dim str4 As String
strappend = Format(Date, "mmddyyyy")
strpath = "c:\field tickets\"
str3 = ActiveSheet.Range("p1")

fsavename = strpath & strappend & str3 & ".xls"
If Dir(fsavename) < "" Then
fsavename = strpath & strappend & str3 & "a.xls"
End If

ActiveWorkbook.Sheets("devon asc f").SaveAs fsavename
Workbooks("fsavename").Close False


This last line is the problem. How do I close this file? All help will be
appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default closing a variable file name with macros

from
Workbooks("fsavename").Close False
to
activeworkbook.Close False

Your problem is due to the fact that fsavename has the path in the filename.
You only need thbe base name

or try this

Dim strappend As String
Dim strpath As String
Dim str3 As String
Dim str4 As String
strappend = Format(Date, "mmddyyyy")
strpath = "c:\field tickets\"
str3 = ActiveSheet.Range("p1")

fsavename = strpath & strappend & str3 & ".xls"
If Dir(fsavename) < "" Then
fsavename = strappend & str3 & "a.xls"
End If

ActiveWorkbook.Sheets("devon asc f").SaveAs strpath & fsavename
Workbooks("fsavename").Close False

I removed strpath from fsavename and then included it as a serate part of
the SAveas.



"bigjim" wrote:

I'm using Excel 2003. I have created a separate workbook from a worksheet
and saved it to my hard drive. I am using the current date as part of the
file name so that it changes daily. All this works fine, but I can't close
the file after I save it. This is what I have now:

Dim strappend As String
Dim strpath As String
Dim str3 As String
Dim str4 As String
strappend = Format(Date, "mmddyyyy")
strpath = "c:\field tickets\"
str3 = ActiveSheet.Range("p1")

fsavename = strpath & strappend & str3 & ".xls"
If Dir(fsavename) < "" Then
fsavename = strpath & strappend & str3 & "a.xls"
End If

ActiveWorkbook.Sheets("devon asc f").SaveAs fsavename
Workbooks("fsavename").Close False


This last line is the problem. How do I close this file? All help will be
appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default closing a variable file name with macros

Yes that worked well. I just used activeworkbook.close and it did just what
I wanted. I really appreciate the help.



"Joel" wrote:

from
Workbooks("fsavename").Close False
to
activeworkbook.Close False

Your problem is due to the fact that fsavename has the path in the filename.
You only need thbe base name

or try this

Dim strappend As String
Dim strpath As String
Dim str3 As String
Dim str4 As String
strappend = Format(Date, "mmddyyyy")
strpath = "c:\field tickets\"
str3 = ActiveSheet.Range("p1")

fsavename = strpath & strappend & str3 & ".xls"
If Dir(fsavename) < "" Then
fsavename = strappend & str3 & "a.xls"
End If

ActiveWorkbook.Sheets("devon asc f").SaveAs strpath & fsavename
Workbooks("fsavename").Close False

I removed strpath from fsavename and then included it as a serate part of
the SAveas.



"bigjim" wrote:

I'm using Excel 2003. I have created a separate workbook from a worksheet
and saved it to my hard drive. I am using the current date as part of the
file name so that it changes daily. All this works fine, but I can't close
the file after I save it. This is what I have now:

Dim strappend As String
Dim strpath As String
Dim str3 As String
Dim str4 As String
strappend = Format(Date, "mmddyyyy")
strpath = "c:\field tickets\"
str3 = ActiveSheet.Range("p1")

fsavename = strpath & strappend & str3 & ".xls"
If Dir(fsavename) < "" Then
fsavename = strpath & strappend & str3 & "a.xls"
End If

ActiveWorkbook.Sheets("devon asc f").SaveAs fsavename
Workbooks("fsavename").Close False


This last line is the problem. How do I close this file? All help will be
appreciated.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default closing a variable file name with macros

Try using

Workbooks(fsavename).Close False


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"bigjim" wrote in message
...
I'm using Excel 2003. I have created a separate workbook from a worksheet
and saved it to my hard drive. I am using the current date as part of the
file name so that it changes daily. All this works fine, but I can't
close
the file after I save it. This is what I have now:

Dim strappend As String
Dim strpath As String
Dim str3 As String
Dim str4 As String
strappend = Format(Date, "mmddyyyy")
strpath = "c:\field tickets\"
str3 = ActiveSheet.Range("p1")

fsavename = strpath & strappend & str3 & ".xls"
If Dir(fsavename) < "" Then
fsavename = strpath & strappend & str3 & "a.xls"
End If

ActiveWorkbook.Sheets("devon asc f").SaveAs fsavename
Workbooks("fsavename").Close False


This last line is the problem. How do I close this file? All help will
be
appreciated.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default closing a variable file name with macros

That makes sense. Thanks a bunch. I'll try it.

"Bob Phillips" wrote:

Try using

Workbooks(fsavename).Close False


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"bigjim" wrote in message
...
I'm using Excel 2003. I have created a separate workbook from a worksheet
and saved it to my hard drive. I am using the current date as part of the
file name so that it changes daily. All this works fine, but I can't
close
the file after I save it. This is what I have now:

Dim strappend As String
Dim strpath As String
Dim str3 As String
Dim str4 As String
strappend = Format(Date, "mmddyyyy")
strpath = "c:\field tickets\"
str3 = ActiveSheet.Range("p1")

fsavename = strpath & strappend & str3 & ".xls"
If Dir(fsavename) < "" Then
fsavename = strpath & strappend & str3 & "a.xls"
End If

ActiveWorkbook.Sheets("devon asc f").SaveAs fsavename
Workbooks("fsavename").Close False


This last line is the problem. How do I close this file? All help will
be
appreciated.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 772
Default closing a variable file name with macros

Try just using Activeworkbook.close. Workbooks expects an index and you are
passing a name, one that does not exist because you have quotes on your
variable...
("fsavename").
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"bigjim" wrote:

I'm using Excel 2003. I have created a separate workbook from a worksheet
and saved it to my hard drive. I am using the current date as part of the
file name so that it changes daily. All this works fine, but I can't close
the file after I save it. This is what I have now:

Dim strappend As String
Dim strpath As String
Dim str3 As String
Dim str4 As String
strappend = Format(Date, "mmddyyyy")
strpath = "c:\field tickets\"
str3 = ActiveSheet.Range("p1")

fsavename = strpath & strappend & str3 & ".xls"
If Dir(fsavename) < "" Then
fsavename = strpath & strappend & str3 & "a.xls"
End If

ActiveWorkbook.Sheets("devon asc f").SaveAs fsavename
Workbooks("fsavename").Close False


This last line is the problem. How do I close this file? All help will be
appreciated.

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
Closing a Workbook if Macros aren't enabled. [email protected] Excel Programming 3 August 9th 07 08:00 PM
Able to preserve value of variable after closing excel? JNW Excel Programming 2 January 13th 07 01:34 AM
Enabling/Disabling Macros w/o closing & re-opening Conan Kelly Excel Programming 1 August 31st 06 12:38 AM
Closing Within Macros bodhisatvaofboogie Excel Programming 9 May 27th 06 03:09 AM
Variable that retains value after closing excel Sandy Excel Programming 2 November 22nd 05 04:25 PM


All times are GMT +1. The time now is 02:34 PM.

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

About Us

"It's about Microsoft Excel"