Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Francisca Perez   on Aug 09 In MS Office Category.

  
Question Answered By: Ludwik Fischer   on Aug 09

code is very good and close, but might I suggest the following
modifications for it to work right:



Sub Extract_Current_Sheet_to_File()

Dim wsToSave As Worksheet

Dim strName As String

On Error Resume Next

strName = ActiveSheet.[a1]

Set wsToSave = Sheets(strName)

If wsToSave Is Nothing Then

MsgBox "There is no sheet  named " & strName & "."

Exit Sub

End If

Application.ScreenUpdating = False

wsToSave.Copy ' copy  this sheet to a new workbook, must use no
parameters

' should do some error checking here:

ActiveWorkbook.SaveAs Filename:=strName ' save  the new workbook

ActiveWorkbook.Close

'or in do the SaveAs and Close in one statement:

'ActiveWorkbook.Close SaveChanges:=True, Filename:=strName

Application.ScreenUpdating = True

If Dir(strName & ".xls") <> vbNullString Then

MsgBox strName & " was saved successfully"

Else

MsgBox strName & " was NOT saved successfully"

End If

End Sub

Share: 

 

This Question has 10 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Save a single sheet as a separate file Or get search suggestion and latest updates.


Tagged: