「Excel VBA シートを設定ファイルとして利用する」の版間の差分
ナビゲーションに移動
検索に移動
2行目: | 2行目: | ||
[[Excel VBA]] | | [[Excel VBA]] | | ||
− | Private Const | + | Private Const COL_VAR_KEY As Integer = 1 |
− | Private Const | + | Private Const COL_VAR_VAL As Integer = 2 |
Private properties As Object | Private properties As Object | ||
Public Sub test() | Public Sub test() | ||
Call loadProperties | Call loadProperties | ||
− | Debug.Print properties.Item(" | + | Debug.Print properties.Item("BASE_DIR") |
End Sub | End Sub | ||
17行目: | 17行目: | ||
Private Sub loadProperties() | Private Sub loadProperties() | ||
Dim sheet As Worksheet | Dim sheet As Worksheet | ||
− | Dim endCel As | + | Dim endCel As Range |
− | Dim | + | Dim eRow As Long |
Dim r As Long | Dim r As Long | ||
24行目: | 24行目: | ||
Set sheet = ActiveWorkbook.Sheets("設定") | Set sheet = ActiveWorkbook.Sheets("設定") | ||
− | Set endCel = sheet. | + | Set endCel = sheet.Range("A1").SpecialCells(xlLastCell) |
− | For r = 1 To endCel. | + | For r = 1 To endCel.Row |
Call properties.Add( _ | Call properties.Add( _ | ||
− | sheet.Cells(r, | + | sheet.Cells(r, COL_VAR_KEY).Text _ |
− | , sheet.Cells(r, | + | , sheet.Cells(r, COL_VAR_VAL).Text) |
Next | Next | ||
End Sub | End Sub |
2022年5月19日 (木) 14:50時点における最新版
Excel VBA シートを設定ファイルとして利用する
- Private Const COL_VAR_KEY As Integer = 1
- Private Const COL_VAR_VAL As Integer = 2
- Private properties As Object
- Public Sub test()
- Call loadProperties
- Debug.Print properties.Item("BASE_DIR")
- End Sub
- '
- ' Excelの"設定"シートから、値を読込みMapに格納する
- ' 1列目:KEY、2列目:値
- '
- Private Sub loadProperties()
- Dim sheet As Worksheet
- Dim endCel As Range
- Dim eRow As Long
- Dim r As Long
- Set properties = CreateObject("Scripting.Dictionary")
- Set sheet = ActiveWorkbook.Sheets("設定")
- Set endCel = sheet.Range("A1").SpecialCells(xlLastCell)
- For r = 1 To endCel.Row
- Call properties.Add( _
- sheet.Cells(r, COL_VAR_KEY).Text _
- , sheet.Cells(r, COL_VAR_VAL).Text)
- Next
- End Sub
© 2006 矢木浩人