Results 1 to 21 of 21

Thread: Question about closing excel.

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Netherlands.
    Posts
    9

    Question about closing excel.

    What vb-code can I put in my macro formula to close the program excel? I use this code to close the document without saving:

    Application.DisplayAlerts = False
    ActiveWorkbook.Close

    This code only closes te document and not the whole excel program. What code can I use for that?

    Thanks for replies!

    Greetz Relli.

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    VB Code:
    1. Application.Quit
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Netherlands.
    Posts
    9
    It doesn't seem to work. Excel remains open.

  4. #4
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    works for me.

    can you paste your code?
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  5. #5
    Si_the_geek
    Guest
    try:
    VB Code:
    1. Application.Quit false

    this will close any open documents (including hidden ones) without saving them, I got that problem before when I had a hidden document open - it tried to ask to save it, but with displayalerts set to false it doesn't show the message

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Netherlands.
    Posts
    9
    Sub Sluiten()
    Application.DisplayAlerts = False
    ActiveWorkbook.Close
    Application.Quit False


    End Sub

  7. #7
    Addicted Member Supester's Avatar
    Join Date
    Nov 2001
    Location
    The Netherlands
    Posts
    220
    Do you have any references to a range object still open....I know there should be a lot of examples dealing with the exact same problem.....
    We have the technology and we are not afraid to use it

  8. #8
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    that's a good point make sure any references, objects etc are destroyed first, i'm not sure what effect they have on VBA for Excel...
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  9. #9

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Netherlands.
    Posts
    9
    I feel there should be a code to close excel. Just simply close, no further problems. But what the code is? Tell me......

  10. #10
    Si_the_geek
    Guest
    Try this:

    ActiveWorkbook.Close False
    Application.Quit False


    also, when testing it try it without "Application.DisplayAlerts = False", it should then hopefully tell you why it isn't closing

  11. #11

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Netherlands.
    Posts
    9
    How should I write the code? Like this?

    Sub Sluiten()
    '

    ActiveWorkbook.Close False
    Application.Quit False


    '
    End Sub

    I am still a VB rookie.
    If it ain't dutch, it ain't much.

  12. #12
    Si_the_geek
    Guest
    yep, that's the way

  13. #13

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Netherlands.
    Posts
    9
    Doesn't work VB doesn't like the .quit text in the code.
    If it ain't dutch, it ain't much.

  14. #14
    Addicted Member djengiz's Avatar
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    153

    Hoi! Probeer dit eens

    Option Explicit

    Public Sub fExcel()

    'excel ****
    Dim objExcel As Excel.Application
    Dim objWorkbook As Excel.Workbook
    Dim objWorksheet As Excel.Worksheet
    Dim objChart As Excel.Chart
    Dim objRng As Range

    Set objRng = Nothing
    Set objChart = Nothing

    exit_Handler:
    'Free up memory, otherwise there will be a memory leak.
    Set objWorksheet = Nothing
    objWorkbook.Close False
    Set objWorkbook = Nothing
    objExcel.Quit
    Set objExcel = Nothing

    Exit Function
    err_handler:
    MsgBox Err.Description, vbInformation
    Err.Number = 0
    Resume exit_Handler
    End Function

  15. #15

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Netherlands.
    Posts
    9
    Jihah, een mede dutchy.

    Hij geeft een foutmelding:

    Compileerfout:

    Exit Function is niet toegestaan in Sub of Property

    Ik wil dus gewoon excel afsluiten met een macro functie. In een excel-sheet dus een knop met afsluiten in plaats van op het kruisje rechtsboven te drukken.

    Help? Alvast bedankt.
    If it ain't dutch, it ain't much.

  16. #16
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    english???

    please
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  17. #17

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Netherlands.
    Posts
    9
    Originally posted by darre1
    english???

    please
    Sorry

    He gave me the function as mentioned above, but it doesn't seem to work. The following error appeared:

    Exit function is not allowed in sub or property.

    If it ain't dutch, it ain't much.

  18. #18
    Addicted Member djengiz's Avatar
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    153

    Sorry, nog een keertje...... Foutje van mij.

    Hoi! Probeer dit eens
    Option Explicit

    Public Sub fExcel()

    'excel ****
    Dim objExcel As Excel.Application
    Dim objWorkbook As Excel.Workbook
    Dim objWorksheet As Excel.Worksheet
    Dim objChart As Excel.Chart
    Dim objRng As Range

    Set objRng = Nothing
    Set objChart = Nothing

    exit_Handler:
    'Free up memory, otherwise there will be a memory leak.
    Set objWorksheet = Nothing
    objWorkbook.Close False
    Set objWorkbook = Nothing
    objExcel.Quit
    Set objExcel = Nothing

    Exit Sub
    err_handler:
    MsgBox Err.Description, vbInformation
    Err.Number = 0
    Resume exit_Handler
    End Sub

  19. #19
    Addicted Member djengiz's Avatar
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    153

    Ben je erg nieuw met programmeren?

    Ik had een funktie geschreven, maar daar het jij nu even niets aan. Je kan het ook als een sub gebruiken. ff koppie-peesten

  20. #20

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Netherlands.
    Posts
    9
    Ik heb hem nu zo staan. Hij geeft echter weer een fout:

    objectvariabele of blokvariabele With is niet opgesteld


    Public Sub fExcel()

    'excel ****
    Dim objExcel As Excel.Application
    Dim objWorkbook As Excel.Workbook
    Dim objWorksheet As Excel.Worksheet
    Dim objChart As Excel.Chart
    Dim objRng As Range

    Set objRng = Nothing
    Set objChart = Nothing

    exit_Handler:
    'Free up memory, otherwise there will be a memory leak.
    Set objWorksheet = Nothing
    objWorkbook.Close False
    Set objWorkbook = Nothing
    objExcel.Quit
    Set objExcel = Nothing

    Exit Sub
    err_handler:
    MsgBox Err.Description, vbInformation
    Err.Number = 0
    Resume exit_Handler
    End Sub
    If it ain't dutch, it ain't much.

  21. #21
    Addicted Member djengiz's Avatar
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    153
    Hoi, ben ik weer. Ik zie dat je macros maakt. post je code maar ff en dan kijk ik wel. Probeer in het vervolg alleen maar engelse versies van microsoft te gebruiken, want je komt geheid in de problemen.

Posting Permissions

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



Click Here to Expand Forum to Full Width