Show and hide fields with default value when opening a Word document in vba RRS feed

  • Question

  • Hi,

    I have a word document .docm (with 2013)with a button. When clicking this button a macro in word is executed for comparing and creating new word documents.

    There are equally in this document just below the button a label and a progressbar for showing the progress of the script, I try to hide these fields until that a click on the button is done. I would like equally to reset the value of these fields when I open the document and I don't know how to do that.

    Here my macro:

    Private Sub SummaryReportButton_Click()
        'Initialize the progressbar and the label
        Dim k As Integer
        Dim filesNumber As Integer
        k = 0
        Me.Label.Caption = "Please wait..."
        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
        Me.Label.Caption = "The comparison process starts..."
        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, _
            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
            objDocC.Close SaveChanges:=True
        End If
            'Update of the progressbar and the label
            k = k + 1
            Me.Label.Caption = k * 100 / filesNumber & "% Completed"
            Me.ProgressBar.Value = k * 100 / filesNumber
        Next objFileA
        Me.Label.Caption = "The process is complete. Comparison reports have been created."
    End Sub

    Could you please help with that?

    Thanks in advance for your help

    Thursday, December 21, 2017 9:23 AM