Sync 对象 (Office)Sync object (Office)

Microsoft Word、 Microsoft Excel 中的Workbook对象和 Microsoft PowerPoint 中的Presentation对象中的Document对象的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 中,通过Workbook对象的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属性不返回NothingThe 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属性是否**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.