Consulting

Results 1 to 5 of 5

Thread: BeforeClose event

  1. #1

    BeforeClose event

    [VBA]
    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
    [/VBA]

    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?

  2. #2
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location
    try hardcoding it int the workbook and when you need to run it use
    [vba]
    call workbook_beforeclose
    [/vba]

  3. #3
    What do you mean hardcoding?

  4. #4
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location
    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

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    this should work from your personal or an addin:
    [VBA]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
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •