调用 UpdateBookmark & useAforB 作为布尔代码辅助
Call UpdateBookmark & useAforB as Boolean code assistance
我一直在本网站上的一些人的帮助下将一些代码放在一起。我 运行 遇到了一些麻烦 - 我正在使用 Call UpdateBookmark
函数将之前输入的信息替换到 word 文档中,但我在将其实现到我现有的代码中时遇到了问题。
Private Sub cmdOk_Click()
Dim useAforB As Boolean
useAforB = CheckBox1.Value
Application.ScreenUpdating = False
With ActiveDocument
Call UpdateBookmark("Lodge", ComboBoxLodge.Value)
Call UpdateBookmark("Form", tbForm.Value)
Call UpdateBookmark("Form2", tbForm.Value)
Call UpdateBookmark("AGN", tbGN.Value)
Call UpdateBookmark("AFN", tbFN.Value)
Call UpdateBookmark("LGN", useAforB, _
tbGN.Value, TBLPGN.Value)
Call UpdateBookmark("RGN", useAforB, _
tbGN.Value, TBLPGN.Value)
Call UpdateBookmark("LFN", useAforB, _
tbFN.Value, TBLPFN.Value)
Call UpdateBookmark("RFN", useAforB, _
tbFN.Value, TBLPFN.Value)
Call UpdateBookmark("DOB", tbDOB.Value)
Call UpdateBookmark("LT", cbLT.Value)
Call UpdateBookmark("PN", tbPN.Value)
Call UpdateBookmark("PN2", tbPN.Value)
Call UpdateBookmark("PN3", tbPN.Value)
Call UpdateBookmark("PN4", tbPN.Value)
Call UpdateBookmark("Issued", tbissue.Value)
Call UpdateBookmark("Expiry", tbexpiry.Value)
Call UpdateBookmark("LTD", tbLTD.Value)
Call UpdateBookmark("LTD2", tbLTD.Value)
Call UpdateBookmark("Narrative", tbNarrative.Value)
Call UpdateBookmark("PRR", tbPRR.Value)
Call UpdateBookmark("Recommendation", cbRecommendation.Value)
End With
Application.ScreenUpdating = True
Unload Me
End Sub
Sub UpdateBookmark(BookmarkToUpdate As String, TextAtBookmark As String)
Dim BookmarkRange As Range
Set BookmarkRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BookmarkRange.Text = TextAtBookmark
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BookmarkRange
End Sub
每当我尝试 运行 代码时,我都会收到一个错误,显示为 Compile error: ByRef argument type mismatch
- 有人能给我一些帮助吗??谢谢大家。
为清楚起见添加了整个代码
Option Explicit
Private Sub CheckBox1_Click()
Dim en As Boolean
en = Not CheckBox1.Value
EnableControls Array(TBLPGN, TBLPFN), en
If CheckBox1.Value = True Then ComboBoxLodge.Value = "Applicant"
If CheckBox1.Value = False Then ComboBoxLodge.Value = "Lodging parent"
End Sub
'utility sub: enable/disable controls
Private Sub EnableControls(cons, bEnable As Boolean)
Dim con
For Each con In cons
With con
.Enabled = bEnable
.BackColor = IIf(bEnable, vbWhite, RGB(200, 200, 200))
End With
Next con
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdClear_Click()
tbForm.Value = Null
tbFN.Value = Null
tbGN.Value = Null
tbdob.Value = Null
cbLT.Value = Null
tbPN.Value = Null
tbissue.Value = Null
tbexpiry.Value = Null
tbLTD.Value = Null
tbNarrative.Value = Null
tbPRR.Value = Null
cbRecommendation.Value = Null
CheckBox1.Value = False
ComboBoxLodge.Value = Null
End Sub
Private Sub cmdOk_Click()
Dim useAforB As Boolean
useAforB = CheckBox1.Value
Application.ScreenUpdating = False
With ActiveDocument
Call UpdateBookmark("Lodge", ComboBoxLodge.Value)
Call UpdateBookmark("Form", tbForm.Value)
Call UpdateBookmark("Form2", tbForm.Value)
Call UpdateBookmark("AGN", tbGN.Value)
Call UpdateBookmark("AFN", tbFN.Value)
Call UpdateBookmark("LGN" useAforB _
tbGN.Value, TBLPGN.Value)
Call UpdateBookmark("RGN", useAforB, _
tbGN.Value, TBLPGN.Value)
Call UpdateBookmark("LFN", useAforB, _
tbFN.Value, TBLPFN.Value)
Call UpdateBookmark("RFN", useAforB, _
tbFN.Value, TBLPFN.Value)
Call UpdateBookmark("DOB", tbdob.Value)
Call UpdateBookmark("LT", cbLT.Value)
Call UpdateBookmark("PN", tbPN.Value)
Call UpdateBookmark("PN2", tbPN.Value)
Call UpdateBookmark("PN3", tbPN.Value)
Call UpdateBookmark("PN4", tbPN.Value)
Call UpdateBookmark("Issued", tbissue.Value)
Call UpdateBookmark("Expiry", tbexpiry.Value)
Call UpdateBookmark("LTD", tbLTD.Value)
Call UpdateBookmark("LTD2", tbLTD.Value)
Call UpdateBookmark("Narrative", tbNarrative.Value)
Call UpdateBookmark("PRR", tbPRR.Value)
Call UpdateBookmark("Recommendation", cbRecommendation.Value)
End With
Application.ScreenUpdating = True
Unload Me
End Sub
Sub UpdateBookmark(BookmarkToUpdate As String, TextAtBookmark As String)
Dim BookmarkRange As Range
Set BookmarkRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BookmarkRange.Text = TextAtBookmark
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BookmarkRange
End Sub
Private Sub Tbform_Change()
tbForm = UCase(tbForm)
End Sub
Private Sub Tbpn_Change()
tbPN = UCase(tbPN)
End Sub
Private Sub tbPRR_Change()
tbPRR = UCase(tbPRR)
End Sub
Private Sub UserForm_Initialize()
With cbLT
.AddItem "lost"
.AddItem "stolen"
End With
With cbRecommendation
.AddItem "I believe there is an entitlement to have the l/t flag turned off as the applicant has not contributed to the loss of Passport number: "
.AddItem "I believe there is no entitlement to have the l/t flag turned off as the applicant has contributed to the loss of Passport number: "
End With
With ComboBoxLodge
.AddItem "Lodging parent"
.AddItem "Applicant"
End With
With CheckBox1
CheckBox1.Value = True
End With
lbl_Exit:
Exit Sub
End Sub
您的 Sub UpdateBookmark
需要两个字符串类型的参数,但在某些情况下您传递了四个参数:不清楚其意图是什么。
你的意思是像
Call UpdateBookmark("LGN", IIf(useAforB, tbGN.Value, TBLPGN.Value))
?
我一直在本网站上的一些人的帮助下将一些代码放在一起。我 运行 遇到了一些麻烦 - 我正在使用 Call UpdateBookmark
函数将之前输入的信息替换到 word 文档中,但我在将其实现到我现有的代码中时遇到了问题。
Private Sub cmdOk_Click()
Dim useAforB As Boolean
useAforB = CheckBox1.Value
Application.ScreenUpdating = False
With ActiveDocument
Call UpdateBookmark("Lodge", ComboBoxLodge.Value)
Call UpdateBookmark("Form", tbForm.Value)
Call UpdateBookmark("Form2", tbForm.Value)
Call UpdateBookmark("AGN", tbGN.Value)
Call UpdateBookmark("AFN", tbFN.Value)
Call UpdateBookmark("LGN", useAforB, _
tbGN.Value, TBLPGN.Value)
Call UpdateBookmark("RGN", useAforB, _
tbGN.Value, TBLPGN.Value)
Call UpdateBookmark("LFN", useAforB, _
tbFN.Value, TBLPFN.Value)
Call UpdateBookmark("RFN", useAforB, _
tbFN.Value, TBLPFN.Value)
Call UpdateBookmark("DOB", tbDOB.Value)
Call UpdateBookmark("LT", cbLT.Value)
Call UpdateBookmark("PN", tbPN.Value)
Call UpdateBookmark("PN2", tbPN.Value)
Call UpdateBookmark("PN3", tbPN.Value)
Call UpdateBookmark("PN4", tbPN.Value)
Call UpdateBookmark("Issued", tbissue.Value)
Call UpdateBookmark("Expiry", tbexpiry.Value)
Call UpdateBookmark("LTD", tbLTD.Value)
Call UpdateBookmark("LTD2", tbLTD.Value)
Call UpdateBookmark("Narrative", tbNarrative.Value)
Call UpdateBookmark("PRR", tbPRR.Value)
Call UpdateBookmark("Recommendation", cbRecommendation.Value)
End With
Application.ScreenUpdating = True
Unload Me
End Sub
Sub UpdateBookmark(BookmarkToUpdate As String, TextAtBookmark As String)
Dim BookmarkRange As Range
Set BookmarkRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BookmarkRange.Text = TextAtBookmark
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BookmarkRange
End Sub
每当我尝试 运行 代码时,我都会收到一个错误,显示为 Compile error: ByRef argument type mismatch
- 有人能给我一些帮助吗??谢谢大家。
为清楚起见添加了整个代码
Option Explicit
Private Sub CheckBox1_Click()
Dim en As Boolean
en = Not CheckBox1.Value
EnableControls Array(TBLPGN, TBLPFN), en
If CheckBox1.Value = True Then ComboBoxLodge.Value = "Applicant"
If CheckBox1.Value = False Then ComboBoxLodge.Value = "Lodging parent"
End Sub
'utility sub: enable/disable controls
Private Sub EnableControls(cons, bEnable As Boolean)
Dim con
For Each con In cons
With con
.Enabled = bEnable
.BackColor = IIf(bEnable, vbWhite, RGB(200, 200, 200))
End With
Next con
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdClear_Click()
tbForm.Value = Null
tbFN.Value = Null
tbGN.Value = Null
tbdob.Value = Null
cbLT.Value = Null
tbPN.Value = Null
tbissue.Value = Null
tbexpiry.Value = Null
tbLTD.Value = Null
tbNarrative.Value = Null
tbPRR.Value = Null
cbRecommendation.Value = Null
CheckBox1.Value = False
ComboBoxLodge.Value = Null
End Sub
Private Sub cmdOk_Click()
Dim useAforB As Boolean
useAforB = CheckBox1.Value
Application.ScreenUpdating = False
With ActiveDocument
Call UpdateBookmark("Lodge", ComboBoxLodge.Value)
Call UpdateBookmark("Form", tbForm.Value)
Call UpdateBookmark("Form2", tbForm.Value)
Call UpdateBookmark("AGN", tbGN.Value)
Call UpdateBookmark("AFN", tbFN.Value)
Call UpdateBookmark("LGN" useAforB _
tbGN.Value, TBLPGN.Value)
Call UpdateBookmark("RGN", useAforB, _
tbGN.Value, TBLPGN.Value)
Call UpdateBookmark("LFN", useAforB, _
tbFN.Value, TBLPFN.Value)
Call UpdateBookmark("RFN", useAforB, _
tbFN.Value, TBLPFN.Value)
Call UpdateBookmark("DOB", tbdob.Value)
Call UpdateBookmark("LT", cbLT.Value)
Call UpdateBookmark("PN", tbPN.Value)
Call UpdateBookmark("PN2", tbPN.Value)
Call UpdateBookmark("PN3", tbPN.Value)
Call UpdateBookmark("PN4", tbPN.Value)
Call UpdateBookmark("Issued", tbissue.Value)
Call UpdateBookmark("Expiry", tbexpiry.Value)
Call UpdateBookmark("LTD", tbLTD.Value)
Call UpdateBookmark("LTD2", tbLTD.Value)
Call UpdateBookmark("Narrative", tbNarrative.Value)
Call UpdateBookmark("PRR", tbPRR.Value)
Call UpdateBookmark("Recommendation", cbRecommendation.Value)
End With
Application.ScreenUpdating = True
Unload Me
End Sub
Sub UpdateBookmark(BookmarkToUpdate As String, TextAtBookmark As String)
Dim BookmarkRange As Range
Set BookmarkRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BookmarkRange.Text = TextAtBookmark
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BookmarkRange
End Sub
Private Sub Tbform_Change()
tbForm = UCase(tbForm)
End Sub
Private Sub Tbpn_Change()
tbPN = UCase(tbPN)
End Sub
Private Sub tbPRR_Change()
tbPRR = UCase(tbPRR)
End Sub
Private Sub UserForm_Initialize()
With cbLT
.AddItem "lost"
.AddItem "stolen"
End With
With cbRecommendation
.AddItem "I believe there is an entitlement to have the l/t flag turned off as the applicant has not contributed to the loss of Passport number: "
.AddItem "I believe there is no entitlement to have the l/t flag turned off as the applicant has contributed to the loss of Passport number: "
End With
With ComboBoxLodge
.AddItem "Lodging parent"
.AddItem "Applicant"
End With
With CheckBox1
CheckBox1.Value = True
End With
lbl_Exit:
Exit Sub
End Sub
您的 Sub UpdateBookmark
需要两个字符串类型的参数,但在某些情况下您传递了四个参数:不清楚其意图是什么。
你的意思是像
Call UpdateBookmark("LGN", IIf(useAforB, tbGN.Value, TBLPGN.Value))
?