VBA code always worked but in excel 2019 crashes excel

Mr Kulle

New Member
Joined
Dec 29, 2014
Messages
23
Hello,

at work they updated excel to 2019 version and now my distribution macro crashes excel.
when following the macro step for step, it looks like the new workbook to copy 1 sheet to doesn't have any sheets :(
VBA Code:
'''''''''''''''''''''' WRITE TO A NETWORK DRIVE ''''''
'''''''''''Dim paths  for filename to cells'''''''''
Sheets("Distribution").Select

Dim Path As String
Dim filename As String
Path = ActiveSheet.Range("E2")
filename = ActiveSheet.Range("D2")

Dim wb As Workbook
  Sheets("KPI").Copy
  Set wb = ActiveWorkbook
      With wb
     Range("A1").Select
ActiveCell.End(xlDown).Offset(2, 0).Select
ActiveCell.End(xlDown).Offset(2, 0).Select
ActiveCell.End(xlDown).Offset(2, 0).Select
Rows(ActiveCell.Row & ":" & Rows.Count).Delete
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs filename:=Path & filename & ".xls", FileFormat:=xlNormal
Application.DisplayAlerts = True
    Application.DisplayAlerts = False
    ActiveWindow.Close
    Application.DisplayAlerts = True
  End With
.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Do you still want to save the workbook as an xls, or do you want to save it as either an xlsx, or xlsm?
 
Upvote 0
Does the path string include the backslashes
VBA Code:
Path = ActiveSheet.Range("E2")
 
Upvote 0
i have 2 different server locations,

example :

W:\SHIP OUT\KPI\USERNAME\KPI\
\\ach-fs-02\pub_lmd$\Receiving instructions\WH Team\USERNAME\KPI\
 
Upvote 0
How about
VBA Code:
ActiveWorkbook.SaveAs Path & filename & ".xlsx", 51
 
Upvote 0
The problem in office 2019 lays within :
Sheets("KPI").Copy

Which should open a new work book and copy the sheet in it.
It does open a new workbook but somehow it is bugged and doesn't show any sheets or grid.
Therefor the actions after this code will cause excel to crash.

I reprogrammed it to below and now it works again :
VBA Code:
'''''''''''''''''''''' WRITE TO A NETWORK DRIVE ''''''
'''''''''''Dim paths for filename to cells'''''''''
Sheets("Distribution").Select

Dim Path As String
Dim filename As String
Path = ActiveSheet.Range("E2")
filename = ActiveSheet.Range("D2")
Dim wb As Workbook

'NEW CODE
Sheets("KPI").Select
Range("A1:Q42").Select
Selection.Copy
Set wb = Workbooks.Add

With wb
Range("A1").Select
ActiveSheet.Paste
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
ActiveCell.End(xlDown).Offset(2, 0).Select
ActiveCell.End(xlDown).Offset(2, 0).Select
ActiveCell.End(xlDown).Offset(2, 0).Select
Rows(ActiveCell.Row & ":" & Rows.Count).Delete
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs filename:=Path & filename & ".xls", FileFormat:=xlNormal
Application.DisplayAlerts = True
Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True
End With

End Sub
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

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