Sdílet prostřednictvím


Save Method

As it applies to the Search object

Saves the search results to a Search Folder.

expression**.Save**(SchFldrName)

*expression   * Required. An expression that returns a Search object.

*SchFldrName   * Required. A string that represents the Search Folder name.

As it applies to the View object

Saves the view, or saves the changes to a view.

expression**.Save**

*expression   * Required. An expression that returns a View object.

As it applies to the other objects in the Applies To list

Saves the Microsoft Outlook item to the current folder or, if this is a new item, to the Outlook default folder for the item type.

expression**.Save**

*expression   * Required. An expression that returns one of the objects in the Applies To list.

Remarks

The Save method displays an error if a Search Folder with the same name already exists.

Example

As it applies to the Search object

The following Microsoft Visual Basic for Applications (VBA) example searches the Inbox for items with Subject line equal to 'Test' and saves the results in a Search Folder. The AdvanceSearchComplete event procedure sets the Boolean blnSearchComp to True when the the search is complete. This Boolean variable is used by the TestAdvancedSearchComplete() procedure to determine when the search is complete. The sample code must be placed in a class module such as ThisOutlookSession, and the TestAdvancedSearchComplete() procedure must be called before the event procedure can be called by Outlook.

Public blnSearchComp As Boolean

Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)
    MsgBox "The AdvancedSearchComplete Event fired"
    blnSearchComp = True
End Sub

Sub TestAdvancedSearchComplete()
    Dim sch As Outlook.Search
    Dim rsts As Outlook.Results
    Dim i As Integer
    blnSearchComp = False
    Const strF As String = "urn:schemas:mailheader:subject = 'Test'"
    Const strS As String = "Inbox"   
    Set sch = Application.AdvancedSearch(strS, strF) 
    While blnSearchComp = False
        DoEvents
    Wend 
    sch.Save("Subject Test")
End Sub

As it applies to the View object

The following VBA example creates a new view called New Table and applies it.

Sub CreateView()
'Creates a new view

    Dim olApp As Outlook.Application
    Dim objName As Outlook.NameSpace
    Dim objViews As Outlook.Views
    Dim objNewView As Outlook.View

    Set olApp = New Outlook.Application
    Set objName = olApp.GetNamespace("MAPI")
    Set objViews = objName.GetDefaultFolder(olFolderInbox).Views
    Set objNewView = objViews.Add(Name:="New Table", _
                     ViewType:=olTableView)
    objNewView.Save
    objNewView.Apply

End Sub

As it applies to the other objects in the Applies To list

This Microsoft Visual Basic/Visual Basic for Applications (VBA) example creates an appointment item and sets the ReminderSet property before saving it.

Sub AddAppointment()
    Dim OutApp As Outlook.Application
    Dim apti As Outlook.AppointmentItem
    Set OutApp = CreateObject("Outlook.Application")
    Set apti = OutApp.CreateItem(olAppointmentItem)
    apti.Subject = "Car Servicing"
    apti.Start = DateAdd("n", 16, Now)
    apti.End = DateAdd("n", 60, apti.Start)
    apti.ReminderSet = True
    apti.ReminderMinutesBeforeStart = 60
    apti.Save
End Sub

If you use Microsoft Visual Basic Scripting Edition (VBScript) in an Outlook form, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript.

Sub CommandButton1_Click()
 Set apti = Application.CreateItem(1)
 apti.Subject = "Car Servicing"
 apti.Start = DateAdd("n", 16, Now)
 apti.End = DateAdd("n", 60, apti.Start)
 apti.ReminderSet = True
 apti.ReminderMinutesBeforeStart = 60
 apti.Save
End Sub

Applies to | AppointmentItem Object | ContactItem Object | DistListItem Object | DocumentItem Object | JournalItem Object | MailItem Object | MeetingItem Object | NoteItem Object | PostItem Object | RemoteItem Object | ReportItem Object | Search Object | TaskItem Object | TaskRequestAcceptItem Object | TaskRequestDeclineItem Object | TaskRequestItem Object | TaskRequestUpdateItem Object | View Object

See Also | SaveAs Method | SaveAsFile Method | Saved Property | SaveSentMessageFolder Property