Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save an Excel file with a new name

Status
Not open for further replies.

PJFry

Technical User
Feb 6, 2005
93
US
I am new to Excel VB and I want to write a routine that will save the current Excel file in same directory as the original, using the same name as the current file with '_External' appended to the end.

The current file is :
C:\Rpt\Richards_June07
The new file will save as
C:\Rpt\Richards_June07_External

The trick is that the location and filename needs to dynamic.

The external file would overwrite anything out there.

I code quite a bit in Access, but the Excel objects are still very new to me.

Ideas?
Thanks in Advance!
PJ
 



Hi,

As I stated in the other forum, turn on your macro recorder and record doing a SaveAs.

Skip,
[sub]
[glasses] To be safe on the [red]FOURTH[/red],
Don't take a [red]FIFTH[/red] on the [red]THIRD[/red]
Or you might not come [red]FORTH[/red] on the [red]FIFTH[/red]
[red][highlight blue]FORTH[/highlight][/red][white][highlight red]WITH[/highlight][/white] [tongue][/sub]
 
ActiveWorkbook.SaveAs (ActiveWorkbook.FullName & "_External")
should work
 
Or this ?
ActiveWorkbook.SaveAs Replace(ActiveWorkbook.FullName, ".xls", "_External.xls")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
The external file would overwrite anything out there
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Replace(ActiveWorkbook.FullName, ".xls", "_External.xls")
Application.DisplayAlerts = True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV,
Maybe you have a newer verion of office but i don't have a replace method but thanks for pointing out the error in my code:
Code:
ActiveWorkbook.SaveAs (Left(ActiveWorkbook.FullName, Len(ActiveWorkbook.FullName) - 4) & "_External")
That Code should work
 
a newer verion of office
My code should work with office 2000 and above.
 
Ah, Still running 97 here. Looks like you've got the better code then
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top