2017-12-18 223 views
0

我有4列,每列有2組複選框,我正在尋找循環遍歷每個集合,並檢查兩個複選框是否都被選中,如果它們然後退出子集並且將該項目的名稱與在msgbox中的一組中選中的2個複選框進行檢查。在Word中循環表格並檢查複選框是否勾選

Set oRow = oTable.Rows 
Set oTable = doc.Tables(3) 
For Each oRow In oTable.Rows 
    With oRow 
     If .Cells(3).Range.Text <> .Cells(3).Range.Text <> "Prep" Or .Cells(3).Range.Text <> "Y" Or .Cells(3).Range.Text <> "" Then 
      If .Cells(3).ParentContentControl.Checked = True And .Cells(4).ParentContentControl.Checked = True Then 'error here 
       MsgBox "The following item has both preparer and reviewer checked:" & .Cells(2) 
       Exit Sub 
      ElseIf .Cells(5).ParentContentControl.Checked = True And .Cell(6).ParentContentControl.Checked = True Then 
       MsgBox .Cell(2) 
       Exit Sub 
      End If 
     End If 
    End With 
Next oRow 

的問題是我不斷收到一個錯誤。

運行時錯誤「438」,對象不支持此屬性或方法。

+0

什麼樣的錯誤? –

+0

運行時錯誤'438',對象不支持此屬性或方法。 – Lowpar

+0

你有什麼樣的複選框,它是'ContentControl'還是'Field'?您能否添加文檔的該部分的屏幕截圖以便更好地理解? –

回答

1

要訪問ContentControl嵌入表,在單元格,則需要以下引用:

If .Cells(3).Range.ContentControls(1).Checked = True And .Cells(4).Range.ContentControls(1).Checked = True Then 
+0

看起來不錯,我會檢查,一個問題,我需要一個以確保在單元格不包含複選框時不嘗試代碼行。就像.Cells(3).Parent.Type = wdContentControlCheckBox你會有什麼想法? – Lowpar

+0

嘗試像這樣:'如果.cells(3).range.contentcontrols.count> 1然後'檢查是否存在任何CC ... –

+0

.Cells(3).Range.ContentControls.Count> 0工作! – Lowpar

相關問題