Copy/Export Multiple Sheets into New Single Workbook Using VBA button

TheRoyAllen

New Member
Joined
Aug 3, 2011
Messages
1
My boss recently asked me to modify an existing spreadsheet we use as a reporting on location at well sites. My experience with excel is mostly on the financial analysis side but I do know a little about VBA.

What I have is a button labeled "EXPORT FIELD DATA" and when you click the button it copies/exports the "Field Data" worksheet into a new workbook. I have been asked to modify this button to export the "Calculation", "Well Head Chart", and "Flow Rates Chart" worksheets along with the "Field Data" sheet. The button is set to run "Sub test3()" the code for which looks like...

Code:
Sub test3()
'
' test3 Macro
' Macro recorded 8/29/2007 by Brad Myers
'
' Keyboard Shortcut: Ctrl+Shift+L
'
    myfilename = Windows(1).Caption
 
    Sheets("FIELD DATA").Select
    Cells.Select
    Selection.Copy
    Workbooks.Add
     newfilename = Windows(2).Caption
    Cells.Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Cells.Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        '
        With ActiveSheet.PageSetup
        .PrintTitleRows = "$1:$14"
        .PrintTitleColumns = "$A:$AE"
    End With
    ActiveSheet.PageSetup.PrintArea = "$A$1:$AE$856"
    With ActiveSheet.PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = "Page &P"
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .LeftMargin = Application.InchesToPoints(0)
        .RightMargin = Application.InchesToPoints(0)
        .TopMargin = Application.InchesToPoints(0)
        .BottomMargin = Application.InchesToPoints(0)
        .HeaderMargin = Application.InchesToPoints(0.25)
        .FooterMargin = Application.InchesToPoints(0.25)
        .PrintHeadings = False
        .PrintGridlines = False
        .PrintComments = xlPrintNoComments
 
        .CenterHorizontally = True
        .CenterVertically = True
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperLegal
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = 70
        .PrintErrors = xlPrintErrorsDisplayed
    End With
    Range("A1").Select
        ActiveWindow.Close
    Range("A1").Select
 
    Windows(myfilename).Activate
 
    Application.CutCopyMode = False
    Sheets("MENU").Select
End Sub

Again I need it to export the 4 worksheets mentioned above into a single workbook. I know you could simply copy the four sheets over into a new workbook manually but that has been deemed "too difficult for the end user". Thanks for your help and let me know if I need to better clarify anything for you.

TheRoyAllen
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,224,508
Messages
6,179,188
Members
452,893
Latest member
denay

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