View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Harlan Grove[_5_] Harlan Grove[_5_] is offline
external usenet poster
 
Posts: 97
Default Dynamic filename

"JC" wrote...
That's a good idea, but will this work if I do a save as
and change the name of the file from foo.xls to
foo1.xls? My variables will still be pointing to foo.xls
thus invalidating my code??? I want to use this as a
template and have users change the filename when they
have a new customer. I don't want them to have to change
the code references.

...

At some point, simple testing becomes a good idea. Add the following macro to a
new workbook then run the macro. What's displayed in the message boxes?


Sub foo()
Dim wb As Workbook, ofn As String

If Dir(Environ("TEMP") & "\foobar.xls") < "" Then
Kill Environ("TEMP") & "\foobar.xls"
End If

Set wb = ActiveWorkbook
wb.Save
ofn = wb.FullName
MsgBox ofn
wb.SaveAs FileName:=Environ("TEMP") & "\foobar.xls"
MsgBox wb.FullName
Workbooks.Open FileName:=ofn
wb.Close SaveChanges:=False
End Sub

--
To top-post is human, to bottom-post and snip is sublime.