randomuser
New Member
- Joined
- Jul 22, 2022
- Messages
- 5
- Office Version
- 365
- Platform
- 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
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