0
我一直在一些代碼一起在這個網站上的人的幫助。我遇到了一些問題 - 我使用Call UpdateBookmark
函數將以前輸入的信息替換爲word文檔,並且在我的現有代碼中遇到了問題。致電UpdateBookmark&useAforB作爲布爾代碼幫助
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
'UpdateBookmark'需要兩個字符串類型的參數,但在某些情況下,您傳遞了四個參數:目前還不清楚它的意圖。你的意思是像'Call UpdateBookmark(「LGN」,IIf(useAforB, tbGN.Value,TBLPGN.Value))''? –
嘿@TimWilliams,試過你的代碼,並且已經修復了它 - 你是一個傳奇人物(想把它作爲答案放在下面,所以我可以選擇你的答案?) –