Sync Object

Sync

The Sync property of the Microsoft Office Word   2003 Document object, the Microsoft Office Excel   2003 Workbook object, and the Microsoft Office PowerPoint   2003 Presentation object returns a Sync object.

Using the Sync Object

Use the Sync object to manage the synchronization of the local and server copies of a shared document stored in a Windows SharePoint Services document workspace. The Status property returns important information about the current state of synchronization. Use the GetUpdate method to refresh the sync status. Use the LastSyncTime, ErrorType, and WorkspaceLastChangedBy properties to return additional information.

See the Status property for additional information on the differences and conflicts that can exist between the local and server copies of shared documents.

Use the PutUpdate method to save local changes to the server. Close and re-open the document to retrieve the latest version from the server when no local changes have been made. Use the ResolveConflict method to resolve differences between the local and the server copies, or the OpenVersion method to open a different version alongside the currently open local version of the document.

The GetUpdate, PutUpdate, and ResolveConflict methods of the Sync object do not return status codes because they complete their tasks asynchronously. The Sync object provides important status information through a single event, which the developer can access through the following application-specific events:

  • in Word, through the Sync event of the Document object or the DocumentSync event of the Application object;
  • in Excel, through the Sync event of the Workbook object or the WorkbookSync event of the Application object;
  • in PowerPoint, through the PresentationSync event of the Application object.

msoSyncEventType

MsoSyncEventType can be one of the following msoSyncEventType constants.
msoSyncEventDownloadInitiated (0)
msoSyncEventDownloadSucceeded (1)
msoSyncEventDownloadFailed (2)
msoSyncEventUploadInitiated (3)
msoSyncEventUploadSucceeded (4)
msoSyncEventUploadFailed (5)
msoSyncEventDownloadNoChange (6)
msoSyncEventOffline (7)

The Sync object model is available whether sharing and synchronization are enabled or disabled on the active document. The Sync property of the Document, Workbook and Presentation objects does not return Nothing when the active document is not shared or synchronization is not enabled. Use the Status property to determine whether the document is shared and whether synchronization is enabled.

Not all document synchronization problems raise trappable run-time errors. After using the methods of the Sync object, it's a good idea to check the Status property; if the Status property is msoSyncStatusError, check the ErrorType property for additional information on the type of error that has occurred.

In many circumstances, the best way to resolve an error condition is to call the GetUpdate method. For example, if a call to PutUpdate results in an error condition, then a call to GetUpdate will reset the status to msoSyncStatusLocalChanges.

Example

The following example demonstrates various methods of the Sync object based on the status of the active document.

    Dim objSync As Office.Sync
    Dim strStatus As String
    Set objSync = ActiveDocument.Sync
    If objSync.Status > msoSyncStatusNoSharedWorkspace Then
        Select Case objSync.Status
            Case msoSyncStatusConflict
                objSync.ResolveConflict msoSyncConflictMerge
                ActiveDocument.Save
                objSync.ResolveConflict msoSyncConflictClientWins
                strStatus = "Conflict resolved by merging changes."
            Case msoSyncStatusError
                strStatus = "Last error type: " & objSync.ErrorType
            Case msoSyncStatusLatest
                strStatus = "Document copies already in sync."
            Case msoSyncStatusLocalChanges
                objSync.PutUpdate
                strStatus = "Local changes saved to server."
            Case msoSyncStatusNewerAvailable
                objSync.GetUpdate
                strStatus = "Local copy updated from server."
            Case msoSyncStatusSuspended
                objSync.Unsuspend
                strStatus = "Synchronization resumed."
        End Select
    Else
        strStatus = "Not a shared workspace document."
    End If
    MsgBox strStatus, vbInformation + vbOKOnly, "Sync Information"
    Set objSync = Nothing

Properties | Application Property | Creator Property | ErrorType Property | LastSyncTime Property | Parent Property | Status Property | WorkspaceLastChangedBy Property

Methods | GetUpdate Method | OpenVersion Method | PutUpdate Method | ResolveConflict Method | Unsuspend Method

Parent Objects

Child Objects