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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Close" Statements for Outlook 1

Status
Not open for further replies.

jisoo22

Programmer
Apr 30, 2001
277
US
Hello!

Can someone tell me what statement I have to use to close an Outlook98 email window and also the Outlook explorer window? I tried using something like this:

Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNamespace.PickFolder
If myFolder Is Nothing Then
Debug.Print "No Folder selected"
Else
myFolder.Display
Set MyItem = myFolder.Items(1)
MyItem.Display
Dim temp
...
If MsgBox("Are you sure you want to delete this record from Outlook?", vbOKCancel, "Warning!") = vbOK Then
MyItem.Delete
myFolder.Close
Else
MyItem.Close
myFolder.Close

End If



I get error messages when I run this ("Argument not optional" it says for both the myFolder.Close and MyItem.Close statements).

Thanks,
Jisoo22
 
First, the close method of the Item object requires a save argument:
Save w/o prompting = 0
Discard w/o saving =1
Prompt for saving = 2

MyItem.Close(1)

Next, there is no close method of a Folder object. You need to reference the Explorer object(FYI - There is no save argument for the close method of the explorer object):

MyFolder.GetExplorer.Close Jon Hawkins
 
Hey thanks, it works great now =) I have one small question, since I'm running a macro from Excel that opens up outlook, do you know the command for making Excel the active window? Having Outlook pop-up in my face is pretty annoying.

Thanks
 
Just reset:

Application.Visible = True

and Excel should come back to the foreground. You'll still see a flicker from the Display of the Outlook folder/item object. Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top