打开word文档时字段的默认值

时间:2017-12-21 07:01:35

标签: progress-bar word-vba default-value

我有一个用于比较和创建新word文档的宏。 在这个脚本中有一个标签和一个进度条,用于显示脚本的进度,我想隐藏这些字段并在我打开文档时重置这些字段的值,但我不知道如何操作。

你可以帮忙吗?

我的剧本:

Private Sub SummaryReportButton_Click()

    'Initialize the progressbar
    Dim k As Integer
    Dim filesNumber As Integer
    k = 0   
    Me.Label.Caption = "0% Completed"
    Me.ProgressBar.Value = k

    Dim objDocA As Word.Document
    Dim objDocB As Word.Document
    Dim objDocC As Word.Document

    Dim objFSO As Scripting.FileSystemObject
    Dim objFolderA As Scripting.Folder
    Dim objFolderB As Scripting.Folder
    Dim objFolderC As Scripting.Folder

    Dim colFilesA As Scripting.Files
    Dim objFileA As Scripting.File

    Dim i As Integer
    Dim j As Integer

    Set objFSO = New FileSystemObject
    Set objFolderA = objFSO.GetFolder(ChooseFolder("Choose the folder with the original documents", ThisDocument.Path))
    Set objFolderB = objFSO.GetFolder(ChooseFolder("Choose the folder with revised documents", ThisDocument.Path))
    Set objFolderC = objFSO.GetFolder(ChooseFolder("Choose the folder for the comparisons documents", ThisDocument.Path))

    Set colFilesA = objFolderA.Files

    'Turn off DisplayAlerts
    Application.DisplayAlerts = wdAlertsNone

    'Number of files in the folder
    filesNumber = objFolderA.Files.Count

    For Each objFileA In colFilesA

    If objFileA.Name Like "*.docx" Then
        Set objDocA = Documents.Open(objFolderA.Path & "\" & objFileA.Name)
        Set objDocB = Documents.Open(objFolderB.Path & "\" & objFileA.Name)
        Set objDocC = Application.CompareDocuments( _
            OriginalDocument:=objDocA, _
            RevisedDocument:=objDocB, _
            Destination:=wdCompareDestinationNew)
        objDocA.Close
        objDocB.Close
        On Error Resume Next
        Kill objFolderC.Path & "\" & objFileA.Name
        On Error GoTo 0

        'Turn off DisplayAlerts
        Application.DisplayAlerts = wdAlertsNone

        objDocC.SaveAs FileName:=objFolderC.Path & "\" & objFileA.Name
        Application.DisplayAlerts = wdAlertsNone
        objDocC.Close SaveChanges:=True

    End If

        'Update the label and the progressbar
        k = k + 1
        Me.ProgressBar.Value = k * 100 / filesNumber
        Me.Label.Caption = k * 100 / filesNumber & "% Completed"

    Next objFileA

End Sub

提前感谢您的帮助。

0 个答案:

没有答案