1

そこで、ユーザーがフォームに入力できるテーブルを作成しました。フォーム全体をクリップボードにコピーするボタンを選択します。ただし、セクションに記入しない場合、または 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
4

1 に答える 1

2

セルの状態をテストするためにサイクルを使用してみてください:

T=1
For x = 1 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
  End If
Next x

T=1 の場合、次の構成で選択を行うことができます。

With ActiveDocument
       Set myRange = .Range(.Tables(2).Rows(1).Cells(1).Range.Start, _
                     .Tables(2).Rows(15).Cells(1).Range.End)
       myRange.Select
       Selection.Copy
    End With
于 2013-05-01T01:21:38.627 に答える