共用方式為


(Access) 的 Module.Lines 屬性

Lines 屬性會傳回包含指定的行或行標準模組或類別模組中的內容字串。 唯讀的 String

語法

運算式LineNumLines (行)

表達 代表 Module 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Line 必要 Long 要傳回的第一行的行號。
NumLines 必要 Long 要傳回的行數。

註解

模組之中的行號是從 1 開始的。 例如,如果您讀取Line引數值為 1 且NumLines變數為 1 的 Lines 屬性,則 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 支援與意見反應