Consulting

Results 1 to 14 of 14

Thread: Solved: Auto Start - Minimized

  1. #1
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,938
    Location

    Solved: Auto Start - Minimized

    Hi,

    One last question pertaining to Excel (my current project). In my add-in, I'm calling an Appointment form. This works only if Outlook is open, else it will give user's a message telling them to open outlook. My question is this: How would I automatically check if OUTLOOK.EXE is in their startup folder, if not, add a shortcut to it. Also, I want it to be immediately minimized.

    Here's the kicker, I'm calling this from Excel. I'd like to be able to do this when the Excel add-in is installed. Outlook experts, if this should be in the Excel help section, just let me know (and sorry 'bout the confusion ). Thanks!

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,710
    Location
    Zack

    See if this gets you started, it will check if Outlook is in your Sartup folder. But this only checks the Startup folder, do you also want to check the registry to see if it is listed to auto open there?

    [vba]
    Option Explicit

    Sub CheckStartUp()

    Dim StartUp As Object
    Dim MyPath As String
    Dim FileName As String
    Dim HasOutlook As Boolean

    Set StartUp = CreateObject("WScript.Shell")
    MyPath = StartUp.SpecialFolders("Startup")
    MyPath = MyPath & "\*"
    FileName = Dir(MyPath, vbDirectory)
    Do While FileName <> ""
    If FileName = "OUTLOOK.lnk" Then
    HasOutlook = True
    Exit Do
    Else
    FileName = Dir
    End If
    Loop
    If HasOutlook Then
    MsgBox "Outlook is in the startup folder."
    Else
    MsgBox "Outlook is NOT in the startup folder."
    End If

    End Sub
    [/vba]

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,938
    Location
    Nice check Jake! Thanks for that!

    So instead of a msgbox, is there a way to create a shortcut in that folder? And how about starting it minimized, any ideas?

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,710
    Location
    Yeah, the message box is just for example. We need API to open Outlook, and we can open it minimized.

    [vba]

    Option Explicit

    Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hWnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

    Sub OpenAnyFile()

    Dim FilePath As String
    Dim FileName As String
    Dim FileToOpen As String

    FilePath = "C:\Program Files\Microsoft Office\Office10"
    FileName = "OUTLOOK.EXE"

    FileToOpen = FilePath & "\" & FileName
    Call ShellExecute(0, "Open", FileToOpen & vbNullString, vbNullString, vbNullString, 2)

    End Sub

    [/vba]

  5. #5
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,710
    Location
    I don't know if it is a good idea to force Outlook or any app to open automatically with Windows since the user may not want this. We can just as easily open it from Excel only when it is needed.

  6. #6
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    Zack,
    Post your code again. Did you modify it to use late binding? Have you tried running it on another system? The code opens Outlook fine from my OL2003 and OLXP, and should work the same on OL2K. I suggest focusing on why the code isn't working as expected on your system rather than creating some sort of workaround.

    Also, are you running code from VBE or from your Add-In? Is there any difference?

    Cheers,
    James
    "All that's necessary for evil to triumph is for good men to do nothing."

  7. #7
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,938
    Location
    No, no difference really. I'm not having problems actually, it's working just fine. I was just thinking about the end user's scheduling appointments through this add-in (calling the Appointment form). If they don't have Outlook, it won't pop-up. And they won't open Outlook except to schedule an appoitment. (A lot of this is me assuming from their experience/preference level. The end user is not going to be very computer savvy.)

    What do you think? I am using early binding for the Appointment procedure call. I can post the code if you'd like, but like I said there's not a problem in the code, it runs just fine. (Thanks to everyone here for that!) What's your take (both of you) on this type of procedure? Do you think it's bad ju-ju to do this, more advantageous, or plum stupid? I'd really like to go about this the best way, but am unsure (and probably too close to the project right now) how to proceed with this. I was thinking about adding to my 'readme.txt' files with additional instructions, maybe a powerpoint to lead them through the basics. Whatcha think?

  8. #8
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    So here's what I understand you saying:

    1. The code works OK and opens Outlook if it exists on the PC.
    2. You may have some users who do not have OL, and you need to account for that possibility.
    3. You are driving the code from Excel using some sort of button or macro.

    Any other issues or concerns? I'll post some code for you to use to detect whether or not OL exists so you can prevent runtime errors.

    James
    "All that's necessary for evil to triumph is for good men to do nothing."

  9. #9
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,938
    Location
    Allow me to clarify, I'm horrible at explaining myself.

    Quote Originally Posted by jamescol
    1. The code works OK and opens Outlook if it exists on the PC.
    My code (currently) just opens an Appointment form from Outlook, using early binding.

    Quote Originally Posted by jamescol
    2. You may have some users who do not have OL, and you need to account for that possibility.
    All user's will have Outlook. I'm trying to account for them not having it Open.

    Quote Originally Posted by jamescol
    3. You are driving the code from Excel using some sort of button or macro.
    This is being called from Excel, correct.

    And the only other concern I have, is this really a good method to persue? If this is more hassle than anything, I'll just make an attempt to explain things to them. I was kinda hoping to 'dummy proof' this thing so it was a no-brainer. All thoughts/suggestions welcome! (please?)

  10. #10
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,710
    Location
    Zack

    Why don't we see if Outlook is open or not with the GetObject function then open it if it isn't already open:

    [vba]

    Dim AppOutLook As Object

    On Error Resume Next
    Set AppOutLook = GetObject(, "Outlook.Application")
    On Error GoTo 0

    If AppOutLook Is Nothing Then
    MsgBox "Need to open Outlook."
    Else
    MsgBox "Outlook is open, so no need to open it."
    End If

    [/vba]

  11. #11
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    Zack,
    The code you have should already open OL if it isn't open. If OL isn't on the PC, the errhandler will trip and display a message. The code opens a hidden instance of OL, so maybe it just appears not loaded. If the Appt form is opening, OL has to be running - check Task Manager to verify.

    Have you actually tested with OL not open and receive an error? I guess I'm still confused over the problem of opening OL

    Maybe your question is how to have OL open so the reminder for the Appt form gets triggered to alert the user?

    James
    "All that's necessary for evil to triumph is for good men to do nothing."

  12. #12
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,938
    Location
    Quote Originally Posted by jamescol
    Maybe your question is how to have OL open so the reminder for the Appt form gets triggered to alert the user?

    Thats' it! Oh boy, I stink at asking questions, eh?! I was just worried that if they don't have Outlook running, they may never even get the reminder for the appointment they set.

    And an instance of Outlook does open with the appointment form, but closes when they save the form.

  13. #13
    VBAX Tutor jamescol's Avatar
    Joined
    May 2004
    Location
    Charlotte, NC
    Posts
    251
    Location
    Zack,
    Create an Outlook shortcut in the Start | Programs | Startup folder.

    The path for the shortcut should be to the Outlook.exe file, and you should use the switch /Recycle.

    <Path>\outlook.exe /recycle

    This shortcut will start OL automatically when the user logs in.

    James
    "All that's necessary for evil to triumph is for good men to do nothing."

  14. #14
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,938
    Location
    Thanks James! I think that may be the easiest way. It's going out to beta tester's next week so I'll have a much better idea then also.

    All your guys' help is very much appreciated!!

Posting Permissions

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