Show and hide fields with default value when opening a Word document
I have a word document with a button. When clicking this button a macro in word is executed for comparing and creating new word documents.
There are equally 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.
Could you please help with that?
My script:
Code:
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
Thanks in advance for your help.