提问人:tehomas 提问时间:10/25/2023 最后编辑:braXtehomas 更新时间:10/25/2023 访问量:34
通过 VBA 的 Word 文档上的复选框 - >运行时错误“5941”
checkboxes on word document via vba -> run time error '5941'
问:
我有一个 excel 图表,根据不同列中的答案(全范围、使用范围、单点比较),应该在属于上述选项之一的相应复选框处做一个叉。基本上,这是一项相当简单的任务,但我总是收到运行时错误 5941:集合的请求成员不存在。而且我不知道为什么,相应的 word 文档中的复选框每个都与 vba 代码中的名称完全相同。我在这里做错了吗? 错误发生在 doctest 行中。FormFields(“Checkox1”)...
Dim appWd As New Word.Application
Dim wbXL As New Excel.Application
Dim userInput As String
userInput = InputBox("Enter the number of WX-Form:", "WX-Form Number")
'for the loop
Dim newInput As String
Dim newRange As String
Dim searchcolumn As Range
Dim Cal_Bereich As String
Dim Lieferanten_Cal_Zertifikate As String
AmountWX = WorksheetFunction.CountIf(Range("A3:A2000"), userInput)
'every row is a formular
For b = 1 To AmountWX
newInput = userInput & " Nr." & b
Sheets("Sheet1").Activate
'first row with userinput should be found
Set searchcolumn = Range("A:A")
For Each cell In searchcolumn
If cell.Value = userInput Then
' when input was found the loop should finish
firstrow = cell.Row
Exit For
End If
Next Zelle
newRange = "B" & firstrow + b - 1
Range(newRange) = newInput
Set appWd = New Word.Application
appWd.Visible = True
Set doctest = appWd.Documents.Add("C:\Users\formular.docx")
doctest.Activate
Sheets("Sheet1").Activate
Application.ScreenUpdating = False
'some bookmark assignements
Cal_Bereich = Application.WorksheetFunction.VLookup(Range(newRange), Range("B3:N2000"), 13, False)
Select Case Cal_Bereich
Case "Full range"
doctest.FormFields(1).CheckBox.Value = True
Case "Use range"
doctest.FormFields("Checkbox2").CheckBox.Value = True
Case "Single point comparison"
doctest.FormFields("Checkbox3").CheckBox.Value = True
End Select
Set Anmeldeformular = Nothing
Set appWord = Nothing
Next b
End Sub
答: 暂无答案
评论
FormFields