我使用了以下代码:
<code><span>Sub PopulateddState()</span>
<code><span> Select Case ActiveDocument.FormFields("ddRegion").Result</span>
<code><span> Case "North"</span>
<code><span> With ActiveDocument.FormFields ("ddState").DropDown.ListEntries</span>
<code><span> .Clear</span>
<code><span> .Add "Michigan"</span>
<code><span> .Add "Ohio"</span>
<code><span> End With</span>
<code><span> Case "South"</span>
<code><span> With ActiveDocument.FormFields ("ddState").DropDown.ListEntries</span>
<code><span> .Clear</span>
<code><span> .Add "Georgia"</span>
<code><span> .Add "Texas"</span>
<code><span> End With</span>
<code><span> Case "East"</span>
<code><span> With ActiveDocument.FormFields ("ddState").DropDown.ListEntries</span>
<code><span> .Clear</span>
<code><span> .Add "New York"</span>
<code><span> .Add "Maine"</span>
<code><span> End With</span>
<code><span> Case "West"</span>
<code><span> With ActiveDocument.FormFields("ddState").DropDown.ListEntries</span>
<code><span> .Clear</span>
<code><span> .Add "California"</span>
<code><span> .Add "Oregon"</span>
<code><span> End With</span>
<code><span> End Select</span>
<code><span> End Sub</span>`
每次我尝试将其输入VBE时都说:
预期的行号或语句或语句结尾
我在做什么错?
答案 0 :(得分:0)
您的代码对我有用,尽管我倾向于使用:
Sub PopulateStates()
Dim FmFldList As ListEntries
With ActiveDocument
Set FmFldList = .FormFields("ddState").DropDown.ListEntries
Select Case .FormFields("ddRegion").Result
Case "North"
With FmFldList
.Clear
.Add "Michigan"
.Add "Ohio"
End With
Case "South"
With FmFldList
.Clear
.Add "Georgia"
.Add "Texas"
End With
Case "East"
With FmFldList
.Clear
.Add "New York"
.Add "Maine"
End With
Case "West"
With FmFldList
.Clear
.Add "California"
.Add "Oregon"
End With
End Select
End With
End Sub
PS:发布代码时,请使用工具栏上的{}符号而不是您自己的标记来选择代码。