Saving out a few active sheets and no PQ connections?

AustSportingPix

New Member
Joined
Oct 5, 2020
Messages
42
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
So a few people are wanting to buy my horse racing ratings. Which is great.
The problem is I don't want them to know how I work out the ratings and where I get the data from.

How can I save a copy of just the active sheets and have no PQ info in the workbook?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
This macro saves the active sheets as a new .xlsx workbook, without any PQ queries or connections.

VBA Code:
Public Sub Save_Active_Sheets_as_XLSX_Workbook()

    Dim xlsxFullName As String
    Dim ws As Worksheet
    Dim i As Long

    xlsxFullName = ThisWorkbook.Path & "\New workbook.xlsx"
    
    Application.ScreenUpdating = False
    
    'Save names of active sheets and ungroup them
    
    ReDim saveSheetNames(1 To ActiveWindow.SelectedSheets.Count) As String
    i = 0
    For Each ws In ActiveWindow.SelectedSheets
        i = i + 1
        saveSheetNames(i) = ws.Name
        ws.Select True
    Next
    
    'Copy the sheets to a new workbook
    
    ThisWorkbook.Worksheets(saveSheetNames).Copy
    
    With ActiveWorkbook
        'Delete queries
        While .Queries.Count > 0
            .Queries(1).Delete
        Wend
        'Delete connections
        While .Connections.Count > 0
            .Connections(1).Delete
        Wend
        'Suppress warning if new workbook already exists
        Application.DisplayAlerts = False
        .SaveAs Filename:=xlsxFullName, FileFormat:=xlOpenXMLWorkbook
        Application.DisplayAlerts = True
        .Close False
    End With
    
    'Regroup active sheets
    
    For i = 1 To UBound(saveSheetNames)
        ThisWorkbook.Worksheets(saveSheetNames(i)).Select False
    Next

    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,685
Members
449,117
Latest member
Aaagu

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