Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How end VB-Script when workbook is closed

Status
Not open for further replies.

Nogi

Technical User
Dec 10, 2004
132
BE
Hi all,

I have a question regarding a script i'm using.

The following script is set to launch an msaccess macro:

Code:
Sub GetAccess()
Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    Application.StatusBar = "Working in MS Access"
    Dim MyAccess As Object
    Set MyAccess = CreateObject("Access.Application")
    MyAccess.OpenCurrentDatabase ActiveWorkbook.Path & "\database.mdb", False, "Mypassword"
    MyAccess.DoCmd.RunMacro "Run"
    MyAccess.Quit
    Application.StatusBar = ""
    ActiveWorkbook.Save
ThisWorkbook.Close
Application.ScreenUpdating = True
End Sub

The problem i'm having is, that after the script makes the workbook close at the end, the script still seems to be running in the background somehow for a quite a long time. Cause when i re-open the excelfile that contains the script, it freezes at opening, and sometimes i can still see the "Working in MsAccess" in the statusbar.

Is there a way to end the script totally when arriving to the "thisworkbook.close"-part?

I've been stuck with this for a long time now but can't find a solution.

Any help is very much appriciated.
 
Sub GetAccess()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.StatusBar = "Working in MS Access"
Dim MyAccess As Object
Set MyAccess = CreateObject("Access.Application")
MyAccess.OpenCurrentDatabase ActiveWorkbook.Path & "\database.mdb", False, "Mypassword"
MyAccess.DoCmd.RunMacro "Run"
MyAccess.Quit
Set MyAccess = Nothing
Application.StatusBar = ""
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.ScreenUpdating = True
`[green]If you dont need any more your Excel running[/green]
Application.Quit
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top