Results 1 to 2 of 2
  1. #1
    Lounger
    Join Date
    Jan 2014
    Posts
    30
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Quit without saving

    Hi,

    I call a powershell script from excel which is successful I need when the powershell script starts excel must quit without any prompt and saving.

    Code:
    Sub powerscript()
    strProgram = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -ExecutionPolicy RemoteSigned -noexit"
    strFile = "&" & Chr(34) & "C:\Duties\Daily.ps1" & Chr(34)
    strCompleteName = strProgram & " " & strFile
    Call Shell(strCompleteName, 1)
    End Sub

  2. #2
    Star Lounger Graham Mayor's Avatar
    Join Date
    Mar 2016
    Location
    Cyprus
    Posts
    69
    Thanks
    0
    Thanked 24 Times in 24 Posts
    You could add the following code to the end of your macro
    Code:
        Excel.Application.DisplayAlerts = False
        For Each WB In Excel.Workbooks
            If Not WB.Saved Then WB.Close SaveChanges:=False
        Next WB
        Excel.Application.Quit
    However for that to work, the code must be in a workbook that is already saved such as the Personal workbook, or if in the active workbook then that too must be saved (as macro enabled). If necessary add the code to save the workbook before running the shell process.
    Graham Mayor - Word MVP
    http://www.gmayor.com

  3. The Following User Says Thank You to Graham Mayor For This Useful Post:

    John_2014 (2016-07-31)

Posting Permissions

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