Thread: [Solved] Compile error in Module
View Single Post
 
Old 04-07-2015, 10:02 AM
ksigcajun ksigcajun is offline Windows 7 64bit Office 2010 64bit
Advanced Beginner
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default Compile error in Module

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 VariantstrPassword 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 ContentControloCC_Clone As ContentControl
 
  vProtectionType 
ActiveDocument.ProtectionType
  On Error Resume Next
  Set oRows 
p_oTargetRow
  
If Error <> 0 Then
    
If Selection.Information(wdWithInTableThen
        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(strLockedLen(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:=vProtectionTypePassword:=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 
Reply With Quote