PDA

View Full Version : Solved: Auto Start - Minimized



Zack Barresse
08-25-2004, 04:53 PM
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 :roll: ). Thanks!

Jacob Hilderbrand
08-25-2004, 05:24 PM
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?


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

Zack Barresse
08-25-2004, 05:42 PM
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?

Jacob Hilderbrand
08-25-2004, 05:53 PM
Yeah, the message box is just for example. We need API to open Outlook, and we can open it minimized.



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

Jacob Hilderbrand
08-25-2004, 05:55 PM
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.

jamescol
08-25-2004, 10:02 PM
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

Zack Barresse
08-26-2004, 08:48 AM
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?

jamescol
08-26-2004, 11:35 AM
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

Zack Barresse
08-26-2004, 11:40 AM
Allow me to clarify, I'm horrible at explaining myself.


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.


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.


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?)

Jacob Hilderbrand
08-26-2004, 02:54 PM
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:



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

jamescol
08-26-2004, 10:18 PM
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

Zack Barresse
08-27-2004, 08:14 AM
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.

jamescol
08-27-2004, 10:57 AM
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

Zack Barresse
08-27-2004, 11:06 AM
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!! :yes