gaurav3715
New Member
- Joined
- Jul 16, 2018
- Messages
- 1
Hi
I am very new in VBA and making it with the help of some friends with limited knowledge on this subject. Expecting any help from forum members to solve this.
As a part of my project I have created a code to copy a Hidden sheet "Sheet1" from "Workbook19" to new work book and save it as "New Workbook".
Also I have one code saved in a regular module "Module19" in "Workbook19" which I want to be copied to "ThisWorkbook" module of "New Workbook".
The code I used to copy a Hidden "Sheet1" from "Workbook19" to new work book and save it as "New Workbook" is as below;
Sub CopyAHiddenWorksheetToNewBook()
Dim WS As Worksheet, WB As Workbook, vFile As String
Set WS = Sheets("Sheet1") 'the hidden sheet you want to copy
vFile = Application.GetSaveAsFilename(WS.Name & ".xlsm", _
"Excel Files,*.xlsm,All Files,*.*")
If LCase(vFile) = "false" Then Exit Sub
Set WB = Workbooks.Add(1)
WS.Copy after:=WB.Sheets(1)
Set WS = WB.Sheets(2)
WS.Visible = xlSheetVisible
Application.DisplayAlerts = False
WB.Sheets(1).Delete
Application.DisplayAlerts = True
WB.SaveAs vFile, xlOpenXMLWorkbookMacroEnabled
Windows("Workbook19.xlsm").Activate
End Sub
And code which I want to copy from a regular module "Module19" to "ThisWorkbook" module of "New Workbook" is as below;
Private Sub Workbook_Open()
With Worksheets("New Workbook")
.EnableOutlining = True
.Protect UserInterfaceOnly:=True
End With
End Sub
Thanks in advance for your support....Gaurav
I am very new in VBA and making it with the help of some friends with limited knowledge on this subject. Expecting any help from forum members to solve this.
As a part of my project I have created a code to copy a Hidden sheet "Sheet1" from "Workbook19" to new work book and save it as "New Workbook".
Also I have one code saved in a regular module "Module19" in "Workbook19" which I want to be copied to "ThisWorkbook" module of "New Workbook".
The code I used to copy a Hidden "Sheet1" from "Workbook19" to new work book and save it as "New Workbook" is as below;
Sub CopyAHiddenWorksheetToNewBook()
Dim WS As Worksheet, WB As Workbook, vFile As String
Set WS = Sheets("Sheet1") 'the hidden sheet you want to copy
vFile = Application.GetSaveAsFilename(WS.Name & ".xlsm", _
"Excel Files,*.xlsm,All Files,*.*")
If LCase(vFile) = "false" Then Exit Sub
Set WB = Workbooks.Add(1)
WS.Copy after:=WB.Sheets(1)
Set WS = WB.Sheets(2)
WS.Visible = xlSheetVisible
Application.DisplayAlerts = False
WB.Sheets(1).Delete
Application.DisplayAlerts = True
WB.SaveAs vFile, xlOpenXMLWorkbookMacroEnabled
Windows("Workbook19.xlsm").Activate
End Sub
And code which I want to copy from a regular module "Module19" to "ThisWorkbook" module of "New Workbook" is as below;
Private Sub Workbook_Open()
With Worksheets("New Workbook")
.EnableOutlining = True
.Protect UserInterfaceOnly:=True
End With
End Sub
Thanks in advance for your support....Gaurav