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

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

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

DeleteLines方法从标准模块或类模块中删除行。The DeleteLines method deletes lines from a standard module or a class module.

语法Syntax

表达式DeleteLines(* * StartLine,* *计数)expression. DeleteLines( ** StartLine, ** Count )

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

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
StartLineStartLine必需RequiredLongLong要删除的起始行的行号。The number of the line from which to begin deleting.
CountCount必需RequiredLongLong要删除的行数。The number of lines to delete.

返回值Return Value

Nothing

注解Remarks

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

若要替换另一条线路一条线,使用ReplaceLine方法。To replace one line with another line, use the ReplaceLine method.

示例Example

下面的示例从模块中删除指定行:The following example deletes a specified line from a module.

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 中搜索常量的声明语句并将其删除。You could call this function from a procedure such as the following, which searches the module Module1 for a constant declaration and deletes it.

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

另请参阅See also

概念Concepts

Module 对象Module Object

© 2018 Microsoft