save as

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi,

I have the following code:

obj.Sheets("Data2").Visible = False
obj.Sheets("Data1").Visible = False
obj.Application.ActiveWorkbook.Close savechanges:=True
obj.Application.DisplayAlerts = True
obj.Quit
Set obj = Nothing

I know that I want to save the spreadsheet as another name before closing it
and saving the changes. sorta like a copy, but with another filename.

I am not sure how and where to add the code to achieve this. HELP!

Thanks in advance,
geebee
 
Use obj.ActiveWorkbook.SaveAs FileName:="MyNewFileName.xls"

This can go wherever appropriate (but before .quit) within the code you
posted.

Barry
 
Thanks,
I just want to make sure that by adding this does not interfere with also
saving the file with its original filename in its original location.
 
Right. Instead of using the .Close statement to do the save, do something
like this:

obj.Sheets("Data2").Visible = False
obj.Sheets("Data1").Visible = False
obj.Application.ActiveWorkbook.Save 'Save the original file
obj.Application.ActiveWorkbook.SaveAs FileName:="NewFileName.xls" 'Save
to the new file
obj.Application.ActiveWorkbook.Close savechanges:=False ' No need to save
here
obj.Application.DisplayAlerts = True
obj.Quit
Set obj = Nothing


Barry
 
not working:
obj.Sheets("Data2").Visible = False
obj.Sheets("Data1").Visible = False
obj.Application.ActiveWorkbook.Save 'Save the original file
obj.Application.ActiveWorkbook.SaveAs FileName:="C:\Documents and
Settings\GB92987\Desktop\test\swatch.xls" 'Saveto the new file
obj.Application.ActiveWorkbook.Close savechanges:=False ' No need to save
here

obj.Quit

I am getting an error message that says "cannot access swatch.xls"

Would filecopy work instead of this approach? If so, what is the syntax?

Thanks in advance,
geebee
 
Hmm. Instead of SaveAs, try SaveCopyAs.

Barry

geebee said:
not working:
obj.Sheets("Data2").Visible = False
obj.Sheets("Data1").Visible = False
obj.Application.ActiveWorkbook.Save 'Save the original file
obj.Application.ActiveWorkbook.SaveAs FileName:="C:\Documents and
Settings\GB92987\Desktop\test\swatch.xls" 'Saveto the new file
obj.Application.ActiveWorkbook.Close savechanges:=False ' No need to save
here

obj.Quit

I am getting an error message that says "cannot access swatch.xls"

Would filecopy work instead of this approach? If so, what is the syntax?

Thanks in advance,
geebee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top