Shell command not Minimizing Focus after opening

gchichester

New member
Local time
Today, 01:39
Joined
Nov 13, 2008
Messages
8
I trying to open Outlook Minimized, before running a subroutine, then close it when sub completes.
This code opens Outlook but doesn't minimize it.
Code:
Sub StartOrdProcess()
'/ Run the Daily Orders .csv Import

Shell "C:\Program Files (x86)\Microsoft Office\Office14\outlook.exe", vbMinimizedFocus

End Sub

Thank you in advance for any and all suggestions

gchichester
 
Take a look at this MSDN article.

https://msdn.microsoft.com/en-us/library/xe736fyk(v=vs.90).aspx

Among other things, I think your syntax is incorrect because your path has a space in it. The article tells you the correct way to manage that.

Since you didn't supply the WAIT option, you don't get an automatic status either.

Finally, I'm not 100% sure about vbMinimizedFocus being right. The article seems to suggest a different syntax.
 
Doc, I think the extra quotes need to be added if there are parameters being sent to the called executable which has a space in the path, to stop the OS being confused as to which is a parameter
eg Need to have
""C:\Program Files (x86)\Microsoft Office\Office14\outlook.exe" X,Y"
where X and Y are switches (if indeed they are appropriate for Outlook)
but not needed for
"C:\ProgramFiles(x86)\MicrosoftOffice\Office14\outlook.exe X, Y"

IIRC, vbMinimizedFocus is an option but I never paid much attention because it just comes up with intellisense options
 
Cronk, all I can do is point to the article. I understand your proviso but I have to admit this is not something I used to do a lot.

Myself, I would have opened an application object and used VBA and automation to make it do what I wanted it to do. Use of a shell is, to me, iffy. IIRC, you can only have one copy of Outlook active on your system at one time, which is why when you do the App object, you have to first try to FIND a copy of Outlook so you can tap into it. You cannot open two Outlook App objects because the second one will fail (and rather quickly as I recall the experiment).

One would presume that there is a lot of code not shown here because the OP's command would only launch Outlook. I see no commands in the given code fragment to trigger a macro, issue a command-line option, or to actually close Outlook. Therefore, we are looking at the tip of an iceberg.
 
I definitely agree with the "iffy" bit, and why use it when automation is available. However I have had need to use Shell with software not having automation available, a few times over the years.

The most recent was only last week where the client, a Department in a local government, wanted data from their Access database uploaded to a remote web server in the form of XML files. Actually, it didn't work but looks like that is because of fire wall settings. So they will have to sort that one out with their IT people.
 
Thanks to both for your thoughts, Sorry I should have posted more of the code, and the real reason for using Shell. It was workaround I needed because I couldn't find a solution for the sub failing at the .send but works fine if i use .Display
It fails and returns a run-time 287

Code:
Option Compare Database
Public Sub NoMopOrds()
Dim ordDate As String
Dim wdDate As String
Dim fname As String
'/ Called if no Mop Orders
'/ Send No Mop Orders Email Message

'/ Turn off user prompts
Application.SetOption "Confirm Action Queries", False

'/ Get the Weekday Name for If statement
    wdDate = WeekdayName(Weekday(Now()))

'/ If weekday is Monday subtract 3 days from date for file name - If not Monday subtract 1 day for email subject day of week
    If wdDate = "Monday" Then
       ordDate = WeekdayName(Weekday(Now() - 3))
    Else
       ordDate = WeekdayName(Weekday(Now() - 1))
    End If

'/ If weekday is Monday subtract 3 days from date for file name - If not Monday subtract 1 day for file name
    If wdDate = "Monday" Then
       fname = "MopOrds_" & DatePart("m", Date) & DatePart("d", Date - 3)
    Else
       fname = "MopOrds_" & DatePart("m", Date) & DatePart("d", Date - 1)
    End If

    Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(olMailItem)
    
    With OutMail
        .To = "gchichester@wilk.us.com"
        .Subject = "No Mop Orders for" & " " & ordDate & ""
        .HTMLBody = "No Mop Orders for" & " " & ordDate & ""
      '/.Display
        .Send
    
    End With
   
    Set OutMail = Nothing
    Set OutApp = Nothing

End Sub
 
gChiChester,

I had a similar problem with my own application...turns out it was security settings on my work computer and MS Office 2010. There is a .dll called redemption that would have allowed me to bypass this, but I knew IT would never allow it to be installed...so live with displaying the email first and then sending it interactively.
 
NauticalGent,
I checked all my security setting thinking it my be the issue, Then I realized I'm using the same code from the same project to send other email with out the error.
I compared both sub and didn't see any issues.
It's error is a real mystery,
 
NauticalGent,
I did the google search for redemption as you suggested, What I found seemed to be a low level programming solution.
To me if it's that deep in the security setting why does the code work using .display?
 
.display stops the application from sending anything automatically, which is why that safeguard is there. Redemption allows you to bypass that.
 

Users who are viewing this thread

Back
Top Bottom