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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

worksheet.saveas File causes Workbook rename

Status
Not open for further replies.

barryp

Programmer
Jan 30, 2002
48
0
0
GB
Hi

I'm new to the power of Excel+VB
I've tried

Path = "c:\temp\test.bat"

Worksheets("Sheet2").Activate
ActiveSheet.SaveAs Filename:=Path, FileFormat:=xlTextPrinter

ActiveSheet.Name = "Sheet2"

I understand why I have to rename the Sheets back again, but why has the Workbook been renamed 'test.bat' ???

Regards
 
Hi
You can't actually save a sheet in that way. You need to move the sheet out of the workbook something like this

Code:
Sub a()
Dim Path As String
Worksheets("Sheet2").Move
Path = "c:\temp\test.bat"
ActiveWorkbook.SaveAs Filename:=Path, FileFormat:=xlTextPrinter
End Sub

What you code is doing is simply saving the active book as test.bat. The code above creates te new book to save with just one worksheet in it.

I hope this helps! I have a feeling, but haven't checked, that there is a FAQ on this.
Good Luck
;-)

If a man says something and there are no women there to hear him, is he still wrong? [ponder]
The faqs ma'am, just the faqs. Get the best from these forums : faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top