Module.Lines 属性 (Access)

Lines 属性返回一个字符串,包含指定的行或标准模块或类模块中的行的内容。 只读 String

语法

表达式 (NumLines)

表达 一个代表 Module 对象的变量。

参数

名称 必需/可选 数据类型 说明
Line 必需 Long 要返回的第一行的编号。
NumLines 必需 Long 要返回的行数。

备注

模块中的行从 1 开始编号。 例如,如果读取 Line 属性, Line 参数的值 为 1, NumLines 参数的值为 1, 则 Lines 属性将返回一个字符串,其中包含模块中第一行的文本。

要插入到模块中的文本行,请使用 InsertLines 方法。

示例

下面的示例从模块中删除指定行:

Function DeleteWholeLine(strModuleName, strText As String) _ 
 As Boolean 
 Dim mdl As Module, lngNumLines As Long 
 Dim lngSLine As Long, lngSCol As Long 
 Dim lngELine As Long, lngECol As Long 
 Dim strTemp As String 
 
 On Error GoTo Error_DeleteWholeLine 
 DoCmd.OpenModule strModuleName 
 Set mdl = Modules(strModuleName) 
 
 If mdl.Find(strText, lngSLine, lngSCol, lngELine, lngECol) Then 
 lngNumLines = Abs(lngELine - lngSLine) + 1 
 strTemp = LTrim$(mdl.Lines(lngSLine, lngNumLines)) 
 strTemp = RTrim$(strTemp) 
 If strTemp = strText Then 
 mdl.DeleteLines lngSLine, lngNumLines 
 Else 
 MsgBox "Line contains text in addition to '" _ 
 & strText & "'." 
 End If 
 Else 
 MsgBox "Text '" & strText & "' not found." 
 End If 
 DeleteWholeLine = True 
 
Exit_DeleteWholeLine: 
 Exit Function 
 
Error_DeleteWholeLine: 
 MsgBox Err & " :" & Err.Description 
 DeleteWholeLine = False 
 Resume Exit_DeleteWholeLine 
End Function

可以从以下过程中调用该函数,该函数在模块 Module1 中搜索常量的声明语句并将其删除。

Sub DeletePiConst() 
 If DeleteWholeLine("Module1", "Const conPi = 3.14") Then 
 Debug.Print "Constant declaration deleted successfully." 
 Else 
 Debug.Print "Constant declaration not deleted." 
 End If 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。