Results 1 to 2 of 2
  1. #1
    ElEmEn is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2013
    Posts
    1

    Closing applications outside of Access?

    I'm new to vba and am still learning. I have two questions about closing opened or potentially open documents, workbooks, and email messages. How do I write into my code to close a specified filepath (word doc or excel workbook) if open? Also, I have a code that exports data from Access into Word and then attaches the word doc to a new message in Outlook. I can't write into the code to close the Word app after attaching it to the message because I need to give the user time to complete their message and the word doc can't be closed until the message has been closed. How do I work around this?



  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    If the document was not opened as a VBA object, the only way I know to close other application files is to terminate all instances of the application. Example:

    ' Author Guy Thomas http://computerperformance.co.uk/
    ' Version 2.7 - December 2010
    ' ------------------------ -------------------------------'
    Option Explicit
    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strProcessKill
    strComputer = "."
    strProcessKill = "'excel.exe'"

    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = " & strProcessKill )
    For Each objProcess in colProcess
    objProcess.Terminate()
    Next
    'WSCript.Echo "Just killed process " & strProcessKill & " on " & strComputer
    'WScript.Quit
    'End of WMI Example of a Kill Process
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Closing access database without saving
    By onaggar in forum Access
    Replies: 7
    Last Post: 12-19-2013, 06:23 PM
  2. Replies: 8
    Last Post: 01-12-2012, 04:02 AM
  3. Access 2010 vs 2003 hiding applications
    By fostekei in forum Programming
    Replies: 1
    Last Post: 12-07-2011, 05:08 PM
  4. Closing Word Document From Access
    By bburton in forum Programming
    Replies: 2
    Last Post: 04-25-2011, 10:23 AM
  5. Replies: 0
    Last Post: 11-14-2009, 07:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums