Skip to content

Instantly share code, notes, and snippets.

@bash0C7
Created January 2, 2012 00:20
Show Gist options
  • Save bash0C7/1548764 to your computer and use it in GitHub Desktop.
Save bash0C7/1548764 to your computer and use it in GitHub Desktop.
ExcelDataRecord.cls
Option Explicit
Private MainKeyCol As Long
Private RowCounter As Long
Private Source As Workbook
Private isReadOnly As Boolean
Property Get EOF() As Boolean
If Source.ActiveSheet.Cells(RowCounter, MainKeyCol) = "" Then
EOF = True
Else
EOF = False
End If
End Property
Property Get item(Index As Long) As Range
Set item = Source.ActiveSheet.Cells(RowCounter, Index)
End Property
Property Let item(Index As Long, Value As Variant)
Source.ActiveSheet.Cells(RowCounter, Index).Value = Value
End Property
Property Let StartRow(vs As Long)
RowCounter = vs
End Property
Property Let MainKey(vs As Long)
MainKeyCol = vs
End Property
Public Function NextRecord()
RowCounter = RowCounter + 1
End Function
Public Function PrevRecord()
RowCounter = RowCounter - 1
End Function
Property Let DataSource(ValueWorkbook As Workbook)
Set Source = ValueWorkbook
End Property
Property Get DataSource() As Workbook
Set DataSource = Source
End Property
Property Let ReadOnly(ValueBool As Boolean)
isReadOnly = ValueBool
End Property
Private Sub Class_Initialize()
MainKeyCol = 2
StartRow = 2
isReadOnly = True
End Sub
Public Sub CloseFile(Optional FileName As String = "")
Dim SaveChange As Boolean
If isReadOnly Then
'保存せずに終了
SaveChange = False
Else
'名前を付けて保存
Source.SaveAs (FileName)
SaveChange = True
End If
Source.Close SaveChanges:=SaveChange
End Sub
Private Sub Class_Terminate()
Set Source = Nothing
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment