Copy worksheet into a new workbook

brendalpzm

Board Regular
Joined
Oct 3, 2022
Messages
58
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
Let's say I have 2 workbooks and i have to create 1

wb1 = workbook with the macro
wb2 = worbook with the info

so I have an activeX button in wb1, when I click it it should copy the KeySheet from wb2, create a new workbook (wb3) and paste the sheet onto this new workbook

Idk if i explained myself :s
 
If your 2nd workbook is not open, as I now understand it to be, select your workbook where you want the sheet saved from in the pop-up.
Code:
Sub Save_Sheet_As_Workbook_B()
Dim wb1 As Workbook, wb2 As Workbook, ws1 As Worksheet, newWb As String
ChDir "C:\Brenda"    '<---- Change to folder where workbook to be opened resides or delete line
Application.ScreenUpdating = False
Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Open(Application.GetOpenFilename(FileFilter:="Excel files (*.xl*), *.xl*", Title:="Select workbook to save sheet from.", MultiSelect:=False))
wb1.Activate
Set ws1 = wb2.Sheets("Sheet1")    '<----- Change required
newWb = ThisWorkbook.Path & "\" & "Name for new workbook here.xlsx"    '<----- Change required
    ws1.Copy
        ActiveWorkbook.SaveAs newWb, 51
        wb2.Close False    '<----- Change to True if wb2 needs saving
    Workbooks("Name for new workbook here.xlsx").Close False    '<----- Change required
Application.ScreenUpdating = True
End Sub

Let me explain once again

I have 2 workbooks
wb1, open, this will have the trigger button
wb2 closed, this has a sheet I need to copy

The trigger button should do this:

Open the wb2 copy the sheet I need > create a new excel workbook > paste the sheet I copied > close the wb2
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
So what is the result, after making changes where required, of the code that is quoted in your Post #11?
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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