Greetings,
This is my first attempt at VBA in Word. I'm used to VBA in Excel and the differences are driving me nuts.
I have code that is supposed to execute before the document is saved. I created a Class Module based on Google results (along with the Register Event Handler sub in ThisDocument & a Module with the Sub Register Event Handler), and placed my code in it as follows:
Code:
Public WithEvents App As Word.Application
Private Sub App_DocumentBeforeSave _
(ByVal Doc As Document, _
SaveAsUI As Boolean, _
Cancel As Boolean)
Qual_Status
Doc_Status
Equip_Status
End Sub
Private Sub Qual_Status()
'Set Qual status to Conditional, Pass or Fail
If OptionButton13 = True Then
Label1 = "CONDITIONAL"
Label1.ForeColor = &H80FF&
End
End If
If OptionButton5 And OptionButton7 And OptionButton71 And OptionButton11 = True Then
Label1 = "PASS"
Label1.ForeColor = &H8000&
Else: Label1 = "FAIL"
Label1.ForeColor = &HC0&
End If
End Sub
Private Sub Doc_Status()
'Set Documentation Status
If OptionButton17 And OptionButton16 And OptionButton15 = True Then
Label2 = "RELEASED"
Label2.ForeColor = &H8000&
Else: Label2 = "In Process"
Label2.ForeColor = &H0&
End If
End Sub
Private Sub Equip_Status()
'Set Equipment status
If Label1 = "PASS" And Label2 = "RELEASED" Then
Label3 = "RELEASE TO PRODUCTION"
Label3.ForeColor = &H8000&
ElseIf Label1 = "PASS" And Label2 = "CONDITIONAL" Then
Label3 = "RELEASE TO PRODUCTION"
Label3.ForeColor = &H80FF&
Else: Label3 = "ON HOLD"
Label3.ForeColor = &H0&
End If
End Sub
It runs when I save but errors out on the 1st Else statement (colored red above) with a 424: Object Required, even though the previous command for Label1 forecolor executed cleanly.
If I put this exact same code in ThisDocument, I can execute each sub manually with no problems.
Any assistance with this would be greatly appreciated.
Thanks,
~ Phil