Table of contents
TOC
折叠目录
展开目录

Module.InsertLines 方法 (访问)Module.InsertLines Method (Access)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

InsertLines方法在标准模块或类模块中插入一行或一组行代码。The InsertLines method inserts a line or group of lines of code in a standard module or a class module.

语法Syntax

表达式InsertLines(* 字符串)expression. **InsertLines( ** Line, ** String* )

表达式_一个表示模块对象的变量。_expression A variable that represents a Module object.

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
LineLine必需RequiredLongLong插入的起始行的行号。The number of the line at which to begin inserting.
StringString必需RequiredStringString要插入到模块中的文本。The text to be inserted into the module.

返回值Return Value

Nothing

注解Remarks

若要添加多个行,固有常量vbCrLf一次包含需要的分行组成_字符串_参数字符串中的位置。该常量将强制回车符和换行符。To add multiple lines, include the intrinsic constant vbCrLf at the desired line breaks within the string that makes up the string argument. This constant forces a carriage return and line feed.

使用InsertLines方法时,参数_line_指定的行在任何现有代码向下移动。When you use the InsertLines method, any existing code at the line specified by the line argument moves down.

在模块中的行从 1 开始编号。要确定一个模块中的行数,请使用CountOfLines属性。Lines in a module are numbered beginning with one. To determine the number of lines in a module, use the CountOfLines property.

示例Example

下面的示例创建一个新窗体、添加一个命令按钮并创建该命令按钮的 Click 事件过程:The following example creates a new form, adds a command button, and creates a Click event procedure for the command button:

Function ClickEventProc() As Boolean 
 Dim frm As Form, ctl As Control, mdl As Module 
 Dim lngReturn As Long 

 On Error GoTo Error_ClickEventProc 
 ' Create new form. 
 Set frm = CreateForm 
 ' Create command button on form. 
 Set ctl = CreateControl(frm.Name, acCommandButton, , , , _ 
 1000, 1000) 
 ctl.Caption = "Click here" 
 ' Return reference to form module. 
 Set mdl = frm.Module 
 ' Add event procedure. 
 lngReturn = mdl.CreateEventProc("Click", ctl.Name) 
 ' Insert text into body of procedure. 
 mdl.InsertLines lngReturn + 1, vbTab &; "MsgBox ""Way cool!""" 
 ClickEventProc = True 

Exit_ClickEventProc: 
 Exit Function 

Error_ClickEventProc: 
 MsgBox Err &; " :" &; Err.Description 
 ClickEventProc = False 
 Resume Exit_ClickEventProc 
End Function

另请参阅See also

概念Concepts

Module 对象Module Object

© 2018 Microsoft