Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if Outlook is opened

Status
Not open for further replies.

gloudo

Programmer
Feb 3, 2002
34
NL
Hi There,
I Have two Questions.

First:

I Have Made A Script That Firstly Shows the dialogbox SaveAs and Secondly Sends the File With Outlook.

The Problem Is When In The SaveAs DialogBox Save Is Pressed
The File Isn't Saved, Witch results in: Error Can't Find File.

Here Is My Code.

Private Sub okbtn_Click()
On Error GoTo Err_okbtn_Click

Dim sFileName As String
Dim objOL As New Outlook.Application
Dim objMail As MailItem
Set objOL = New Outlook.Application
Set objMail = objOL.CreateItem(olMailItem)

sFileName = Application.GetSaveAsFilename( _
fileFilter:="Microsoft Excel-Werkmap(*.xls), *.xls")

If sFileName <> &quot;False&quot; Then
GoSub Exit_okbtn_Click

ElseIf sFileName <> &quot;True&quot; Then
GoSub Mail
End If

Mail:

With objMail
.To = Form1.sReciptxt.Text
.CC = &quot;Hans Zwennes&quot;
.Subject = &quot;Probleemhoek Formulier&quot; & &quot; &quot; & Date
.Body = &quot;Dit Is een Test&quot;
.Display
.Attachments.Add sFileName
End With

Exit_okbtn_Click:
Set objMail = Nothing
Set objOL = Nothing
Unload Form1
Exit Sub

Err_okbtn_Click:
MsgBox Err.Description
Resume Exit_okbtn_Click

End Sub

Second:

Is There A Way To Check if Outlook is opened from Excel?
If Not then, Open It after The Check.

The Problem Is That the Form Has to work on the company network, Where Outlook is opened by some central program-lancher.

Thanks,
 
Hi Gloudo

A couple of things have struck me with your query - firstly if it isn't saving when pressing save in the Save As Dialog box then perhaps your version of Office has become corrupt?? Just a thought.

Secondly why dont you just get it to save the workbook at the beginning of the procedure with code like (for example):

ActiveWorkbook.Save
sfilename = ActiveWorkbook.Name

Finally I am not familiar with a central mail system such as you describe but if you are using createobject with an application that is not open wont it throw up an error you could trap and then go on to launch the application?

Just quick thoughts but I hope they help. All the best.
 
As for your second question:
You could use the GetObject method to see if an instance of Outlook is already opened. It will return an error if it's not.
Code:
Dim oOutlook As Object

On Error Resume Next

Set oOutlook = GetObject(,&quot;Outlook.Application&quot;)

If Err.Number <> 0 Then  'Not Opened so Open It
    Err.Clear
    Set oOutlook = CreateObject(&quot;Outlook.Application&quot;)
End If

On Error Goto ErrHndlr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top