Reputation: 155
I have a query in my sheet. I need to export the query range into a new .xlsx workbook to a variable folder (SaveAs).
How can I SaveAs a specific range?
I tried the Application.FileDialog(msoFileDialogSaveAs)
, which does save the entire workbook, but I just want to save a specific range of the workbook.
Sub SaveAsDialog()
On Error Resume Next
With Application.FileDialog(msoFileDialogSaveAs)
If .Show = 0 Then
Exit Sub
End If
Application.DisplayAlerts = False
.Execute
Application.DisplayAlerts = True
End With
End Sub
Upvotes: 1
Views: 2103
Reputation: 6664
You are looking for something like this:
Sub SaveAsDialog()
Dim od As Workbook, nod As Workbook
Set od = ThisWorkbook
'Copy data that you want to save
od.Worksheets("Sheet1").Range("A1:B10").Copy
' Add a new workbook
Set nod = Workbooks.Add
nod.Worksheets(1).Range("A1").PasteSpecial xlPasteValues
'Save the new workbook
nod.SaveAs od.Path & "\New_Book.xlsx"
nod.Close True
End Sub
Upvotes: 1