aliaslamy2k
Active Member
- Joined
- Sep 15, 2009
- Messages
- 416
- Office Version
- 2019
- Platform
- Windows
Dear Experts,
I have below code which works perfectly fine in excel 2019 but it gives me an error when I run the same in excel 2013 on another laptop.
Error is "Error Occured while exporting. Try again". Please help if the code needs to be modified.
Sub Export_to_excel_ActualVSBudget()
On Error GoTo err
Dim xlApp As New Excel.Application
Dim xlWB As New Workbook
Set xlWB = xlApp.Workbooks.Add
'xlWB.Add
xlApp.Visible = False
ThisWorkbook.Activate
Range("A9").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
xlApp.Visible = True
xlWB.Activate
xlWB.Sheets("Sheet1").Select
xlWB.Sheets("Sheet1").Range("B2").PasteSpecial Paste:=xlPasteValues
xlWB.Sheets("Sheet1").Cells.Select
xlWB.Sheets("Sheet1").Cells.EntireColumn.AutoFit
xlWB.Sheets("Sheet1").Range("A2").Select
Exit Sub
err:
MsgBox ("Error Occured while exporting. Try again")
End Sub
I have below code which works perfectly fine in excel 2019 but it gives me an error when I run the same in excel 2013 on another laptop.
Error is "Error Occured while exporting. Try again". Please help if the code needs to be modified.
Sub Export_to_excel_ActualVSBudget()
On Error GoTo err
Dim xlApp As New Excel.Application
Dim xlWB As New Workbook
Set xlWB = xlApp.Workbooks.Add
'xlWB.Add
xlApp.Visible = False
ThisWorkbook.Activate
Range("A9").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
xlApp.Visible = True
xlWB.Activate
xlWB.Sheets("Sheet1").Select
xlWB.Sheets("Sheet1").Range("B2").PasteSpecial Paste:=xlPasteValues
xlWB.Sheets("Sheet1").Cells.Select
xlWB.Sheets("Sheet1").Cells.EntireColumn.AutoFit
xlWB.Sheets("Sheet1").Range("A2").Select
Exit Sub
err:
MsgBox ("Error Occured while exporting. Try again")
End Sub