D
Damil4real
I have a workbook of about 26 worksheets. Since it’s pretty big, I
disabled the save & saveas so the user can only save the current sheet
(the current sheet is copied to another workbook) and the user is
given an option to saveas (saveas dialog) pops up.
The Private Sub Workbook is in the Workbook while the Sub SavingFile
is in the module. The code works well because most of the time, there
is only one visible sheet, so the code copies the one sheet to another
workbook for saving.
The problem is that sometimes, the visible sheets are more than one
sheet. In cases where there are more than one sheets visible, I want
the macro to be able to copy all visible sheets to another workbook
and pop up a saveas dialog so the user can still select what to name
the file.
The code I have right now is pasted below. The Private Sub Workbook is
in the Workbook while the Sub SavingFile is in the module.
I appreciate your assistance!
Thanks!
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
' Following line will prevent all saving
Cancel = True
' Following line will prevent the Save As Dialog box from
showing
If SaveAsUI Then SaveAsUI = False
Response = MsgBox(prompt:="Select 'Yes to Save File' or 'No to
Cancel'.", Buttons:=vbYesNo)
If Response <> vbYes Then Exit Sub
Call SavingFile
End Sub
------------
Sub SavingFile()
Cells.Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
Range("A1").Select
ActiveWorkbook.SaveAs Filename:= _
Application.GetSaveAsFilename(FileN, filefilter:="Excel Files
(*.xls),*.xls")
ActiveWindow.Close
Range("D1").Select
MsgBox "File saved!"
End Sub
disabled the save & saveas so the user can only save the current sheet
(the current sheet is copied to another workbook) and the user is
given an option to saveas (saveas dialog) pops up.
The Private Sub Workbook is in the Workbook while the Sub SavingFile
is in the module. The code works well because most of the time, there
is only one visible sheet, so the code copies the one sheet to another
workbook for saving.
The problem is that sometimes, the visible sheets are more than one
sheet. In cases where there are more than one sheets visible, I want
the macro to be able to copy all visible sheets to another workbook
and pop up a saveas dialog so the user can still select what to name
the file.
The code I have right now is pasted below. The Private Sub Workbook is
in the Workbook while the Sub SavingFile is in the module.
I appreciate your assistance!
Thanks!
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
' Following line will prevent all saving
Cancel = True
' Following line will prevent the Save As Dialog box from
showing
If SaveAsUI Then SaveAsUI = False
Response = MsgBox(prompt:="Select 'Yes to Save File' or 'No to
Cancel'.", Buttons:=vbYesNo)
If Response <> vbYes Then Exit Sub
Call SavingFile
End Sub
------------
Sub SavingFile()
Cells.Select
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
Range("A1").Select
ActiveWorkbook.SaveAs Filename:= _
Application.GetSaveAsFilename(FileN, filefilter:="Excel Files
(*.xls),*.xls")
ActiveWindow.Close
Range("D1").Select
MsgBox "File saved!"
End Sub