Not sure what's going on, but the code was working fine yesterday. Now today I receive the following error message.
"Compile error in hidden module: Module1
This error commonly occurs when code is incompatible with the version, platform or architecture of this application."
Here is my code to add a new row in a table. It errors out on the very last Msg Box.
PHP Code:
Option Explicit
Public p_oTargetRow As Word.Row
Sub InsertRowWithContent()
Dim vProtectionType As Variant, strPassword As String
Dim oRows As Word.Row
Dim iRow As Long
Dim oRng As Word.Range
Dim lngIndex As Long
Dim strLocked As String
Dim arrLocked() As String
Dim oCC_Master As ContentControl, oCC_Clone As ContentControl
vProtectionType = ActiveDocument.ProtectionType
On Error Resume Next
Set oRows = p_oTargetRow
If Error <> 0 Then
If Selection.Information(wdWithInTable) Then
Set oRows = Selection.Rows(1)
End If
End If
If Not oRows Is Nothing Then
Application.ScreenUpdating = False
If vProtectionType <> wdNoProtection Then
strPassword = ""
ActiveDocument.Unprotect Password:=strPassword
End If
With Selection
iRow = oRows.Index
With .Tables(1)
If .Rows.Count > iRow Then
iRow = iRow + 1
oRows.Range.Copy
For Each oCC_Master In .Rows(iRow).Range.ContentControls
strLocked = oCC_Master.LockContentControl & ","
oCC_Master.LockContentControl = False
Next oCC_Master
strLocked = Left(strLocked, Len(strLocked) - 1)
.Rows.Add .Rows(iRow)
Set oRng = .Rows(iRow).Range
oRng.MoveEnd wdCharacter, -1
oRng.Paste
arrLocked = Split(strLocked, ",")
For lngIndex = 1 To UBound(arrLocked)
.Rows(iRow).Range.ContentControls(lngIndex + 1).LockContentControl = arrLocked(lngIndex)
Next lngIndex
Else
.Rows.Last.Range.Copy
.Rows.Add
Set oRng = .Rows.Last.Range
oRng.MoveEnd wdCharacter, -1
oRng.Paste
iRow = iRow + 1
End If
With .Rows(iRow)
For lngIndex = 1 To .Previous.Range.ContentControls.Count
Set oCC_Master = .Previous.Range.ContentControls(lngIndex)
Set oCC_Clone = .Range.ContentControls(lngIndex)
With oCC_Clone
#If VBA7 Then
If Int(Application.Version) >= 14 Then
If .Type = wdContentControlCheckBox Then
.Checked = False
End If
End If
#End If
If .Type = wdContentControlRichText Or _
.Type = wdContentControlText Or _
.Type = wdContentControlDate Then
If Not .ShowingPlaceholderText Then
.Range.Text = ""
End If
End If
If .Type = wdContentControlDropdownList Or .Type = wdContentControlComboBox Then
.DropdownListEntries(1).Select
End If
If .Type = wdContentControlPicture Then
If Not .ShowingPlaceholderText Then
If .Range.InlineShapes.Count > 0 Then
.Range.InlineShapes(1).Delete
.Range.InlineShapes(1).Width = oCC_Master.Range.InlineShapes(1).Width
End If
End If
End If
If .Type = wdContentControlDate Then .Range.Text = ""
.LockContentControl = oCC_Master.LockContentControl
End With
Next lngIndex
End With
End With
End With
If vProtectionType > -1 Then
ActiveDocument.Protect Type:=vProtectionType, Password:=strPassword
End If
Application.ScreenUpdating = False
Set p_oTargetRow = Nothing
Else
MsgBox "The cursor must be locate in a table row containing content controls.", _
vbInformation vbOKOnly, "INVALID SELECTION"
End If
End Sub