Hi
I have a VBA script were a range of cells are saved in a new xlsx file. The VBA script works fine on only one thing.
How do I save also the column width and row height from the original file to the saved file?
At this moment I have this script:
Option Explicit
Sub SaveXLSX()
Dim Filename As Variant
Dim Wb As Workbook
Dim Source As Range, Dest As Range
With Blad1
'Refer to the data cells
Set Source = .Range("A1:K10")
'Build the file name (same result as your code, just to show another way)
'Filename = Join(Array(.Range("P29"), .Range("P30"), .Range("P31")))
Filename = Range("A2")
End With
'Ask the user
Filename = Application.GetSaveAsFilename(Filename, "Excelfile (*.xlsx), *.xlsx")
'Aborted?
If VarType(Filename) = vbBoolean Then Exit Sub
'Create a new file
Set Wb = Workbooks.Add(xlWBATWorksheet)
'Refer to the destination cell
Set Dest = Wb.Sheets(1).Range("A1")
'Copy the cells
Source.Copy Dest
'Alternatively to remove the formulas if any:
'Source.Copy
'Dest.PasteSpecial xlPasteValuesAndNumberFormats
'Save the file
Wb.SaveAs Filename
'Application.ScreenUpdating = True
End Sub
I have a VBA script were a range of cells are saved in a new xlsx file. The VBA script works fine on only one thing.
How do I save also the column width and row height from the original file to the saved file?
At this moment I have this script:
Option Explicit
Sub SaveXLSX()
Dim Filename As Variant
Dim Wb As Workbook
Dim Source As Range, Dest As Range
With Blad1
'Refer to the data cells
Set Source = .Range("A1:K10")
'Build the file name (same result as your code, just to show another way)
'Filename = Join(Array(.Range("P29"), .Range("P30"), .Range("P31")))
Filename = Range("A2")
End With
'Ask the user
Filename = Application.GetSaveAsFilename(Filename, "Excelfile (*.xlsx), *.xlsx")
'Aborted?
If VarType(Filename) = vbBoolean Then Exit Sub
'Create a new file
Set Wb = Workbooks.Add(xlWBATWorksheet)
'Refer to the destination cell
Set Dest = Wb.Sheets(1).Range("A1")
'Copy the cells
Source.Copy Dest
'Alternatively to remove the formulas if any:
'Source.Copy
'Dest.PasteSpecial xlPasteValuesAndNumberFormats
'Save the file
Wb.SaveAs Filename
'Application.ScreenUpdating = True
End Sub