そこで、ユーザーがフォームに入力できるテーブルを作成しました。フォーム全体をクリップボードにコピーするボタンを選択します。ただし、セクションに記入しない場合、または NA と入力した場合は、フォームのコピーを無効にしたいと思います。現在、フォームがこれを行う場合、下のセルに NA または空白の回答が残っている場合にのみ機能します。テーブル全体 (セル 1 ~ 15) を含めるように範囲を編集するにはどうすればよいですか? 以下は私のコードです。(編集:回答として改訂されましたが、要求されたメンバーが存在しないというエラーが発生しました。FormFieldsはテーブルの行2から始まります。
Private Sub Contactcopy_Click()
' Contact Copy Macro
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If
T = 1
For X = 2 To 15
Set r = ActiveDocument.Tables(2).Rows(X).Cells(1).Range.FormFields(1)
If ((r = "NA") Or (r = "")) Then
MsgBox "BLANK QUESTION OR NA ENTERED"
T = 0
Exit For
Else
With ActiveDocument
Set myRange = .Range(.Tables(2).Rows(2).Cells(1).Range.Start, _
.Tables(2).Rows(15).Cells(1).Range.End)
myRange.Select
Selection.Copy
End With
End If
Next X
'Reprotect the document.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub