Sync 对象 (Office)Sync object (Office)

Microsoft Word 中的Document对象、microsoft Excel 中的工作簿对象和 Microsoft PowerPoint 中的Presentation对象的sync属性将返回一个Sync对象。The Sync property of the Document object in Microsoft Word, the Workbook object in Microsoft Excel, and the Presentation object in Microsoft PowerPoint returns a Sync object.

备注

自 Microsoft Office 2010 开始,此对象或成员已弃用,不应再行使用。Beginning with Microsoft Office 2010, this object or member has been deprecated and should not be used.

备注Remarks

使用Sync对象可管理 SharePoint 网站上存储的共享文档的本地副本和服务器副本的同步。Use the Sync object to manage the synchronization of the local and server copies of a shared document stored on a SharePoint site. Status 属性返回有关同步当前状态的重要信息。The Status property returns important information about the current state of synchronization. 使用 GetUpdate 方法刷新同步状态。Use the GetUpdate method to refresh the sync status. 使用 LastSyncTimeErrorTypeWorkspaceLastChangedBy 属性返回的其他信息。Use the LastSyncTime, ErrorType, and WorkspaceLastChangedBy properties to return additional information.

有关共享文档的本地副本和服务器副本之间可能存在的差异和冲突的其他信息, 请参阅Status属性。See the Status property for additional information about the differences and conflicts that can exist between the local and server copies of shared documents.

使用 PutUpdate 方法将本地更改保存到服务器。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. 使用 ResolveConflict 方法可解决本地副本和服务器副本之间的差异,或者使用 OpenVersion 方法可在当前打开的文档的本地版本旁打开另一版本。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.

Sync 对象 GetUpdatePutUpdateResolveConflict 方法不返回状态代码由于以异步方式完成其任务。The GetUpdate, PutUpdate, and ResolveConflict methods of the Sync object do not return status codes because they complete their tasks asynchronously. Sync 对象通过单个事件提供重要的状态信息,开发人员可以通过以下应用程序特定事件来访问这些信息:The Sync object provides important status information through a single event, which the developer can access through the following application-specific events:

  • 在 Word 中, 通过Document对象的Sync事件或Application对象的DocumentSync事件。In Word, through the Sync event of the Document object or the DocumentSync event of the Application object.

  • 在 Excel 中, 通过工作簿对象的Sync事件或Application对象的WorkbookSync事件。In Excel, through the Sync event of the Workbook object or the WorkbookSync event of the Application object.

  • 在 Microsoft PowerPoint 中, 通过Application对象的PresentationSync事件。In Microsoft PowerPoint, through the PresentationSync event of the Application object.

上述 Sync 事件返回一个 msoSyncEventType 值。The Sync event described above returns an msoSyncEventType value.

Sync 对象模型是否共享也可启用或禁用活动文档同步。The Sync object model is available whether sharing and synchronization are enabled or disabled on the active document. 当活动文档未处于共享状态或未启用同步时,文档工作簿演示文稿对象的Sync属性不返回任何内容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. 使用 Status 属性可确定文档是否共享以及是否启用同步。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. 使用Sync对象的方法之后, 最好检查Status属性;如果Status属性为**msoSyncStatusError, 请检查ErrorType**属性以了解有关所发生错误类型的其他信息。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.

在许多情况下, 解决错误条件的最佳方式是调用GetUpdate方法。In many circumstances, the best way to resolve an error condition is to call the GetUpdate method. 例如,如果调用 PutUpdate 导致的错误条件时, GetUpdate 调用可以将状态置为 msoSyncStatusLocalChangesFor example, if a call to PutUpdate results in an error condition, a call to GetUpdate will reset the status to msoSyncStatusLocalChanges.

示例Example

下面的示例将基于活动文档的状态说明 Sync 对象的多种方法。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

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.