Thread: [Solved] If condition not working.
View Single Post
 
Old 06-15-2019, 03:45 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

A better way (IMHO) would be:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
 Application.ScreenUpdating = False
 Dim i As Long, StrDetails As String, StrOffice As String, StrHdFt As String
 With CCtrl
  If .Title = "OFFICE" Then
    For i = 1 To .DropdownListEntries.Count
      If .DropdownListEntries(i).Text = .Range.Text Then
        StrDetails = .DropdownListEntries(i).Value
        Exit For
      End If
    Next
    If StrDetails = "" Then StrDetails = "||"
    StrOffice = Split(StrDetails, "|")(0)
     With ActiveDocument.SelectContentControlsByTitle("A-OFFICE")(1)
      .LockContents = False
      .Range.Text = StrOffice
      .LockContents = False
     End With
    With ActiveDocument.SelectContentControlsByTitle("A-OFFICE")(2)
      .LockContents = False
      .Range.Text = StrOffice
      .LockContents = True
    End With
    With ActiveDocument.SelectContentControlsByTitle("A-OFFICE")(3)
      .LockContents = False
      .Range.Text = StrOffice
      .LockContents = True
    End With
    With ActiveDocument.SelectContentControlsByTitle("OFFICEADDRESS")(1)
      .LockContents = False
      .Range.Text = Replace(Split(StrDetails, "|")(1), ";", Chr(11))
      .LockContents = True
    End With
    Select Case StrOffice
      Case "OFFICENAME1": StrHdFt = "OFFICENAME1 HEADER|OFFICENAME1 FOOTER1|OFFICENAME1 FOOTER2|OFFICENAME1 FOOTER3"
      Case "OFFICENAME2": StrHdFt = "OFFICENAME1 HEADER|OFFICENAME1 FOOTER1|OFFICENAME1 FOOTER2|OFFICENAME1 FOOTER3"
      Case Else: StrHdFt = "|||"
    End Select
    With ActiveDocument.SelectContentControlsByTitle("OFFICEHEAD")(1)
      .LockContents = False
      .Range.Text = Split(StrHdFt, "|")(0)
      .LockContents = True
    End With
    With ActiveDocument.SelectContentControlsByTitle("A-FOOTER1")(1)
      .LockContents = False
      .Range.Text = Split(StrHdFt, "|")(1)
      .LockContents = True
    End With
    With ActiveDocument.SelectContentControlsByTitle("A-FOOTER2")(1)
      .LockContents = False
      .Range.Text = Split(StrHdFt, "|")(2)
      .LockContents = True
    End With
    With ActiveDocument.SelectContentControlsByTitle("A-FOOTER3")(1)
      .LockContents = False
      .Range.Text = Split(StrHdFt, "|")(3)
      .LockContents = True
    End With
  End If
 End With
 Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote