| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

「Excel VBA シートを設定ファイルとして利用する」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
 
2行目: 2行目:
 
[[Excel VBA]] |  
 
[[Excel VBA]] |  
  
  Private Const COL_VA[[R]]_KEY   As Integer = 1
+
  Private Const COL_VAR_KEY   As Integer = 1
  Private Const COL_VA[[R]]_VAL   As Integer = 2
+
  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("BASE_DI[[R]]")
+
     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 [[R]]ange
+
     Dim endCel  As Range
     Dim e[[R]]ow   As Long
+
     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.[[R]]ange("A1").SpecialCells(xlLastCell)
+
     Set endCel = sheet.Range("A1").SpecialCells(xlLastCell)
 
      
 
      
     For r = 1 To endCel.[[R]]ow
+
     For r = 1 To endCel.Row
 
         Call properties.Add( _
 
         Call properties.Add( _
                   sheet.Cells(r, COL_VA[[R]]_KEY).Text _
+
                   sheet.Cells(r, COL_VAR_KEY).Text _
                 , sheet.Cells(r, COL_VA[[R]]_VAL).Text)
+
                 , sheet.Cells(r, COL_VAR_VAL).Text)
 
     Next
 
     Next
 
  End Sub
 
  End Sub

2022年5月19日 (木) 14:50時点における最新版

Excel VBA シートを設定ファイルとして利用する

Excel VBA |

  1. Private Const COL_VAR_KEY As Integer = 1
  2. Private Const COL_VAR_VAL As Integer = 2
  3. Private properties As Object
  4.  
  5. Public Sub test()
  6. Call loadProperties
  7. Debug.Print properties.Item("BASE_DIR")
  8. End Sub
  9.  
  10. '
  11. ' Excel"設定"シートから、値を読込みMapに格納する
  12. ' 1列目:KEY、2列目:値
  13. '
  14. Private Sub loadProperties()
  15. Dim sheet As Worksheet
  16. Dim endCel As Range
  17. Dim eRow As Long
  18. Dim r As Long
  19. Set properties = CreateObject("Scripting.Dictionary")
  20. Set sheet = ActiveWorkbook.Sheets("設定")
  21. Set endCel = sheet.Range("A1").SpecialCells(xlLastCell)
  22. For r = 1 To endCel.Row
  23. Call properties.Add( _
  24. sheet.Cells(r, COL_VAR_KEY).Text _
  25. , sheet.Cells(r, COL_VAR_VAL).Text)
  26. Next
  27. End Sub