使用 ActiveDatasheet 屬性可以和 Screen 對(duì)象一起來標(biāo)識(shí)或引用獲得焦點(diǎn)的數(shù)據(jù)表。Form 對(duì)象,只讀。
expression 必需。返回“應(yīng)用于”列表中的一個(gè)對(duì)象的表達(dá)式。
ActiveDatasheet 屬性設(shè)置包含了在運(yùn)行時(shí)獲得焦點(diǎn)的數(shù)據(jù)表對(duì)象。
此屬性僅在使用宏或 Visual Basic 時(shí)才可用,并且在所有視圖中具有只讀屬性。
您可以使用該屬性來引用活動(dòng)數(shù)據(jù)表及其一個(gè)屬性或方法。例如,下面的代碼使用 ActiveDatasheet 屬性引用活動(dòng)數(shù)據(jù)表中選定區(qū)域的第一行。
TopRow = Screen.ActiveDatasheet.SelTop
下面的示例使用 ActiveDatasheet 屬性標(biāo)識(shí)獲得焦點(diǎn)的數(shù)據(jù)表單元格,如果同時(shí)選定多個(gè)單元格,則定位于選定區(qū)域中的第一行第一列。
Public Sub GetSelection()
' This procedure demonstrates how to get a pointer to the
' current active datasheet.
Dim objDatasheet As Object
Dim lngFirstRow As Long
Dim lngFirstColumn As Long
Const conNoActiveDatasheet = 2484
On Error GoTo GetSelection_Err
Set objDatasheet = Screen.ActiveDatasheet
lngFirstRow = objDatasheet.SelTop
lngFirstColumn = objDatasheet.SelLeft
MsgBox "The first item in this selection is located at " & _
"Row " & lngFirstRow & ", Column " & _
lngFirstColumn, vbInformation
GetSelection_Bye:
Exit Sub
GetSelection_Err:
If Err = conNoActiveDatasheet Then
MsgBox "No data sheet is active.", vbExclamation
Resume GetSelection_Bye
End If
End Sub