Copy "code" from "regular module" of Book1 to "This Workbook module" of Book2

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
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top