'/////////////////////////////////////////////////////////////
          '
                      -ワークシート內のデータの初期化を行う-
          '
          /////////////////////////////////////////////////////////////
          Function CmdClear()
              
          Dim sakiSH As Worksheet
              
          Beep
                  
          Set sakiSH = ThisWorkbook.Sheets(2'転記先のシート
                  sakiSH.Range("A4:O1000").ClearContents
                  sakiSH.Range(
          "A4:O1000").Clear
                  
          Set sakiSH = Nothing
          End Function

          '/////////////////////////////////////////////////////////////
          '
          paintCellsLine
          '
          使い方:
          '
              Dim startCell As Range
          '
              Dim endCell   As Range
          '
              Set startCell = Workbooks(1).Sheets(2).Cells(4, 1)
          '
              Set endCell   = Workbooks(1).Sheets(2).Cells(48, 9)
          '
              Call paintCellsLine(startCell, endCell)
          '
          @param startCell
          '
          @param endCell
          '
          /////////////////////////////////////////////////////////////
          Function paintCellsLine(startCell As Range, endCell As Range)
              
          With Range(startCell, endCell)
                  
          For i = 7 To 12
                      .Borders(i).LineStyle 
          = xlContinuous
                  
          Next
              
          End With
          End Function

          VBA連DB
          Dim sqlStr As String
                      sqlStr 
          = getSqlStr()
                  
          Dim connection As New ADODB.connection
                  
          Dim resultSet As ADODB.recordSet
                  
          Dim connStr As String
                      connStr 
          = "Provider=SQLOLEDB;Server=127.0.0.1;Database=BMS;Trusted_Connection=yes;Uid=sa;Pwd="
                      connection.Open connStr
                      
          Set resultSet = New ADODB.recordSet
                      resultSet.Open sqlStr, connection

          Dictionary的使用(add Microsoft Scripting Runtime.)
          Dim dict

          ' 創建Dictionary
          Set dict = CreateObject("Scripting.Dictionary")

          ' 增加項目
          dict.Add "A"300
          dict.Add 
          "B"400
          dict.Add 
          "C"500

          ' 統計項目數
          = dict.Count

          ' 刪除項目
          dict.Remove ("A")

          ' 判斷字典中是否包含關鍵字
          dict.exists ("B")

          ' 取關鍵字對應的值,注意在使用前需要判斷是否存在key,否則dict中會多出一條記錄
          Value = dict.Item("B")

          ' 修改關鍵字對應的值,如不存在則創建新的項目
          dict.Item("B"= 1000
          dict.Item(
          "D"= 800

          ' 對字典進行循環
          = dict.keys
          = dict.Items
          For i = 0 To dict.Count - 1
            key 
          = k(i)
            Value 
          = v(i)
            
          MsgBox key & Value
          Next

          ' 刪除所有項目
          dict.Removeall

          VBA編程黃金法則:
          錄制宏,修改錄制的宏為己所用

          posted on 2010-09-08 18:15 Ying-er 閱讀(309) 評論(0)  編輯  收藏 所屬分類: VBA
          主站蜘蛛池模板: 镇雄县| 织金县| 大冶市| 容城县| 香港| 康乐县| 济阳县| 基隆市| 廊坊市| 精河县| 神木县| 凤翔县| 东方市| 紫金县| 和平县| 南丰县| 绥化市| 麻阳| 墨玉县| 伊川县| 铁力市| 尉犁县| 襄樊市| 徐水县| 韶山市| 视频| 鹿邑县| 石泉县| 黑龙江省| 东乡族自治县| 徐闻县| 拉萨市| 平安县| 体育| 富裕县| 张家口市| 梁平县| 五华县| 始兴县| 永丰县| 商都县|