PDA

View Full Version : BeforeClose event



next
03-14-2008, 12:05 PM
Sub Workbook_BeforeClose()
Dim decision As VbMsgBoxResult

decision = MsgBox("Overwrite LTD Open?", vbYesNo + vbQuestion)
If decision = vbYes Then ThisWorkbook.SaveAs "S:\xxxxxx\LTD\LTD Open.xls", xlExcel9795
If decision = vbNo Then ThisWorkbook.Close
End Sub


My problem is that the file that needs to run this is in "dif" format, and if i save it in "ThisWorkbook" macro always dissapears. Is there a way to make this a module and just call it out from my Personal Workbook?

Trevor
03-14-2008, 12:49 PM
try hardcoding it int the workbook and when you need to run it use

call workbook_beforeclose

next
03-14-2008, 12:52 PM
What do you mean hardcoding?

Trevor
03-14-2008, 05:00 PM
it is code that is in the program/application, and is "wittin in stone" its a part of the application itself not a macro or a batchfile, that may retrieve values based upon an action that would occurr
Note: hardcoding usualy apples to programming launges ie: C, C+, C++ where you would develope a whole program in that langage, Sorry for confusing you, if I did
simply just put the code in your code section and insttead of calling a macro you call the function name
ie call functionname (where function name is the name of the function or sub you want to call

lucas
03-14-2008, 09:34 PM
this should work from your personal or an addin:
Sub a()
With ActiveWorkbook
Dim decision As VbMsgBoxResult

decision = MsgBox("Overwrite LTD Open?", vbYesNo + vbQuestion)
If decision = vbYes Then ThisWorkbook.SaveAs "S:\xxxxxx\LTD\LTD Open.xls", xlExcel9795
If decision = vbNo Then ThisWorkbook.Close
End With
End Sub