Excel crashes on ".save as" in macro

cknnugget

New Member
Joined
Jun 29, 2020
Messages
44
Office Version
  1. 365
Platform
  1. Windows
The macro was working before but now it crashes on step "'3. Save new workbook in specified file and close copy".
The address was confirmed in immediate window and looks correct
?Worksheets(Sheet9.Name).Range("C4")&Range("E51")
D:\Test items\Memos\1 Pending\2022-10-16-Name--Memo-20.xlxs
However, it saves the file as File for type and then crashes excel
"D:\Test items\Memos\1 Pending\6D9D5C40"
Here is the Macro any Ideas why it would continue to crash??
Dim path As String
path = Worksheets(Sheet9.Name).Range("C4")
Dim memono As Long
memono = Range("A1")
Dim fname As String
fname = Range("E39")
Dim Answer As VbMsgBoxResult
Answer = MsgBox("Memo cannot be changed. Review all and copy to ICHRT before submitting. Click Yes to Save & no to continue working", vbYesNo, "REVIEW MEMO & SAVE")
If Answer = vbYes Then
Application.DisplayAlerts = False
'1. Create copy of Memo in a new Workbook
Worksheets(Sheet4.Name).Visible = True
Worksheets(Array(Sheet1.Name, Sheet4.Name)).Copy
Worksheets(Sheet4.Name).Visible = False
'2. Remove Buttons from copy

'3. Save new workbook in specified file and close copy
With ActiveWorkbook
.SaveAs Filename:=path & fname, FileFormat:=51
.Close
End With
'4. Hide Sheet
Worksheets(Sheet4.Name).Visible = False
'5. Clear Template
Range("C8:L8").ClearContents
Range("C10:L10").ClearContents
Range("C12:L12").ClearContents
Range("C14:L14").ClearContents
Range("C16:L16").ClearContents
Range("C18:L18").ClearContents
Range("C20:H20").ClearContents
'6. update Memo number on template
Sheets(Sheet1.Name).Unprotect Password:=""
Range("A1") = memono + 1
Range("I20:J20").ClearContents
Sheets(Sheet1.Name).Protect Password:=""
'7. Save Template
ThisWorkbook.Save
Application.DisplayAlerts = True
'8.Message Process complete
MsgBox "The Memo has been saved and is pending review. You can now close the Memo Template"
Else
Exit Sub
End If




End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
excels crash ever so often.. why not try and see if your autorecovered file behaves? if it does, just save as there :)
 
Upvote 0
The address was confirmed in immediate window and looks correct
?Worksheets(Sheet9.Name).Range("C4")&Range("E51")
D:\Test items\Memos\1 Pending\2022-10-16-Name--Memo-20.xlxs

fname = Range("E39")
Where's your filename? E39 or E51? What's in E39? Just "6D9D5C40"?

What exactly do you mean by "crashes Excel"? What happens?

Have you shown all your code, e.g. have you omitted any code here:

VBA Code:
'2. Remove Buttons from copy
'?????
'3. Save new workbook in specified file and close copy

that might be making ThisWorkbook the ActiveWorkbook, which you close?
 
Upvote 0
Where's your filename? E39 or E51? What's in E39? Just "6D9D5C40"?

What exactly do you mean by "crashes Excel"? What happens?

Have you shown all your code, e.g. have you omitted any code here:

VBA Code:
'2. Remove Buttons from copy
'?????
'3. Save new workbook in specified file and close copy

that might be making ThisWorkbook the ActiveWorkbook, which you close?
Ah! I see it..

This line is questionable
With ActiveWorkbook
.SaveAs Filename:=path & fname, FileFormat:=51
.Close
End With
better assign new workbook to a different var and then close that..
 
Upvote 0
Where's your filename? E39 or E51? What's in E39? Just "6D9D5C40"?

What exactly do you mean by "crashes Excel"? What happens?

Have you shown all your code, e.g. have you omitted any code here:

VBA Code:
'2. Remove Buttons from copy
'?????
'3. Save new workbook in specified file and close copy

that might be making ThisWorkbook the ActiveWorkbook, which you close?
E51 is the file name. I do not know where "6D9D5C40" comes from instead of naming the file random text is generated for the file name
 
Upvote 0
E51 is the file name. I do not know where "6D9D5C40" comes from instead of naming the file random text is generated for the file name
When when the excel copy is generated, the workbook partially shows on the screen. there is about a 5 second pause then excel shuts down.
 
Upvote 0
Hi,

should the extension not be xlsx?

?Worksheets(Sheet9.Name).Range("C4")&Range("E51")
D:\Test items\Memos\1 Pending\2022-10-16-Name--Memo-20.xlxs

Ciao,
Holger
 
Upvote 0
You haven't answered this question:
Have you shown all your code .... ?

Does it make any difference if you do this?

Rich (BB code):
Dim wbCopy As Workbook

'....

Worksheets(Array(Sheet1.Name, Sheet4.Name)).Copy
Set wbCopy = ActiveWorkbook

'....

With wbCopy
    .SaveAs Filename:=Path & fname, FileFormat:=51
    .Close
End With
 
Upvote 0
Solution

Forum statistics

Threads
1,215,681
Messages
6,126,191
Members
449,298
Latest member
Jest

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