VBA, Save a new copy of WB with tables turned to ranges and connections removed?

randomuser

New Member
Joined
Jul 22, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Could anyone help with VBA to save a copy of the workbook as xls with all tables converted to ranges and then connections deleted? My goal is to save as an independent xlsx doc with connections removed. I currently use a macro that creates a copy combining designated sheets, breaks links in it and saves as xls and although I get an error, it still works. I can't figure out how to tell it to also change all tables to ranges and then delete connections in that new book. Is that possible and does that sound like it would accomplish what I'm wanting to do?


Sub Save_Report()

Dim TheActiveWindow As Window

Dim TempWindow As Window

With ActiveWorkbook

Set TheActiveWindow = ActiveWindow

Set TempWindow = .NewWindow

.Sheets(Array("Sheet1", "Sheet2", “Sheet3”, “Sheet4”)).Copy

'TheActiveWindow.SelectedSheets.Copy

ActiveWorkbook.SaveAs Filename:="C:\Users\me\Documents\documentname .xlsx" _

, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False



End With

With ActiveWorkbook

.Worksheets("Sheet1").ListObjects(1).Unlink

Application.DisplayAlerts = False

.Worksheets("Sheet2").ListObjects(1).Unlink

Application.DisplayAlerts = False

.Worksheets("Sheet3").ListObjects(1).Unlink

Application.DisplayAlerts = False

.Worksheets("Sheet4").ListObjects(1).Unlink

Application.DisplayAlerts = True

.Close True

End With



End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
To add to this question, when I record a macro for this it saves everything but there's no trace of removing connections. It saves as a working copy xlsm, then turns all tables into ranges and saves as xslx to two locations. While recording I'm removing the connections after converting tp ranges but when I go back and run it, the removal of connections isn't there and it's like it never happened in the code. Any ideas?
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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