Module.InsertText 方法 (Access)
InsertText 方法會將指定的文字字串插入標準模組或類別模組。
語法
運算式。插入文字 (文字)
表達 代表 Module 物件的變數。
參數
名稱 | 必要/選用 | 資料類型 | 描述 |
---|---|---|---|
文字 | 必要 | String | 要插入模組中的文字。 |
傳回值
無
註解
當您使用 InsertText 方法來插入字串時,Microsoft Access 將置於新的文字結尾處的模組完成所有其他程序。
若要新增多行,請在構成Text引數的字串內,于所需的分行符號中包含內部常數vbCrLf。 此常數強制換行並換行符號。
若要指定在哪個列插入文字,可用 InsertLines 方法。 若要程式碼插入模組的宣告區段中,使用 InsertLines 方法而不是 InsertText 方法。
注意事項
[!注意事項] 在舊版的 Microsoft Access 中, InsertText 方法是 Application 物件的方法。 您仍然可以使用Application物件的InsertText方法,但我們建議您改用Module物件的InsertText方法。
範例
下列範例會將文字字串插入標準模組中。
Function InsertProc(strModuleName) As Boolean
Dim mdl As Module, strText As String
On Error GoTo Error_InsertProc
' Open module.
DoCmd.OpenModule strModuleName
' Return reference to Module object.
Set mdl = Modules(strModuleName)
' Initialize string variable.
strText = "Sub DisplayMessage()" & vbCrLf _
& vbTab & "MsgBox ""Wild!""" & vbCrLf _
& "End Sub"
' Insert text into module.
mdl.InsertText strText
InsertProc = True
Exit_InsertProc:
Exit Function
Error_InsertProc:
MsgBox Err & ": " & Err.Description
InsertProc = False
Resume Exit_InsertProc
End Function
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。