Activeworkbook.close Problems ?

wichien

New Member
Joined
Mar 14, 2002
Messages
11
I write VBA Code. In during Code Command I use command to Activate another Sheet after finish this file Job. I want to go back to the old file and do some command more, but when I use Activeworkbook.Close !! It's will be End Sub Automatically (Even I have more Procedure to write ) How can I solve This question ?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Can you explain in a little more detail? Maybe you could also show some of your code and let us know exactly where your problem lies...
 
Upvote 0
I use This command for set UndoPoint by put SetunoPoint before change the File and use UndoMacro sub to call the old File back but when the processing it will stop ,I mean the Process go to End sub Automatically when the process go to Activeworkbook.close Line. Do you have any Idea to run it for complete the Sub Process. Thanks.

dim ww
Sub SetUndoPoint()
WW = ThisWorkbook.Path & "" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
ActiveWorkbook.SaveCopyAs WW & ".xlu"
End Sub
Sub UndoMacro()
Application.ScreenUpdating = False
WW = ThisWorkbook.Path & "" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
ActiveWorkbook.SaveAs WW & ".tmp" 'à¾×èÍà»ç¹¡ÒûԴ File.xls
Workbooks.Open WW & ".xlu" 'àÃÕ¡ File ·Õè¡è͹à»ÅÕè¹á»Å§¡ÅѺÁÒ
Application.DisplayAlerts = False
Sheets(zz).Select
ActiveWorkbook.SaveAs WW & ".xls" 'à»ÅÕ蹪×èÍà»ç¹ª×èÍà´ÔÁ
Kill WW & ".xlu"
Workbooks.Open WW & ".tmp" 'àÃÕ¡ä¿Åì¹ÕéÁÒà¾×èÍ Kill
ActiveWorkbook.Close
Kill WW & ".tmp"
 
Upvote 0
You might want to try the following:

Application.ScreenUpdating = False
ww = ThisWorkbook.Path & "" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs ww & ".tmp"
Workbooks.Open ww & ".xlu"
ActiveWorkbook.SaveAs ww & ".xls"
Kill ww & ".xlu"
Application.DisplayAlerts = True
Workbooks(ww & ".tmp").Close (False)

HTH
 
Upvote 0
Thanks BabyTiger,But the Command Line
Workbooks(ww & ".tmp").Close (False)
Still error!! so I write the Whole Command for anybody can see again maybe have other idea to Help. First I call SubDeleteA1 after that I call Sub UndoMacro but it will error on
Workbooks(ww & ".tmp").Close (False) ,So any idea ? Thanks.

dim ww

Sub DeleteA1()
SetUndoPoint
Range("A1").value = ""
End Sub

Sub SetUndoPoint()
WW = ThisWorkbook.Path & "\" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
ActiveWorkbook.SaveCopyAs WW & ".xlu"
End Sub

Sub UndoMacro()
Application.ScreenUpdating = False
WW = ThisWorkbook.Path & "\" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
ActiveWorkbook.SaveAs WW & ".tmp" 'Close File.xls
Workbooks.Open WW & ".xlu" 'Call old File before Change
Application.DisplayAlerts = False
Sheets(zz).Select
ActiveWorkbook.SaveAs WW & ".xls" 'change name to the old one
Kill WW & ".xlu"
Application.DisplayAlerts = True
Workbooks(ww & ".tmp").Close (False) ** Problem Line
Kill WW & ".tmp"
End sub
 
Upvote 0

Forum statistics

Threads
1,214,544
Messages
6,120,126
Members
448,947
Latest member
test111

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