Forum Discussion

FabricioAmaral's avatar
FabricioAmaral
Copper Contributor
Jan 29, 2024

Excel closing by itself after executing recorded macro. How to fix?

Excel closing by itself after executing recorded macro. How to fix? (translated via Google Translate, there may be errors)

Macro:

Sub ClassiftLancamentosGerais()
'
' ClassiftLancamentosGerais Macro
'

'
Range("tLancamentosGerais").Select
ActiveWorkbook.Worksheets("Lançamentos Gerais").ListObjects( _
"tLancamentosGerais").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Lançamentos Gerais").ListObjects( _
"tLancamentosGerais").Sort.SortFields.Add2 Key:=Range( _
"tLancamentosGerais[Vencimento]"), SortOn:=xlSortOnValues, Order:= _
xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Lançamentos Gerais").ListObjects( _
"tLancamentosGerais").Sort.SortFields.Add2 Key:=Range( _
"tLancamentosGerais[Item]"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Lançamentos Gerais").ListObjects( _
"tLancamentosGerais").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("B16").Select
End Sub

  • To resolve the issue of Excel closing unexpectedly after running a macro, refine your macro to avoid unnecessary selections, implement error handling, and manage application settings for improved performance. Test the macro in a clean environment to rule out file-specific issues and ensure your Excel installation and add-ins are functioning correctly.

Resources