'/////////////////////////////////////////////////////////////
          '
                      -ワークシート內(nèi)のデータの初期化を行う-
          '
          /////////////////////////////////////////////////////////////
          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

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

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

          ' 統(tǒng)計項目數(shù)
          = dict.Count

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

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

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

          ' 修改關(guān)鍵字對應(yīng)的值,如不存在則創(chuàng)建新的項目
          dict.Item("B"= 1000
          dict.Item(
          "D"= 800

          ' 對字典進行循環(huán)
          = 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 閱讀(303) 評論(0)  編輯  收藏 所屬分類: VBA
          主站蜘蛛池模板: 永年县| 搜索| 保康县| 天门市| 双鸭山市| 木兰县| 炉霍县| 余庆县| 团风县| 恩平市| 博爱县| 舒城县| 元氏县| 视频| 惠来县| 漠河县| 宝兴县| 大安市| 广安市| 包头市| 聊城市| 静海县| 舞钢市| 灵川县| 印江| 乌审旗| 太康县| 小金县| 攀枝花市| 靖远县| 武邑县| 常山县| 台前县| 醴陵市| 江口县| 洪湖市| 横峰县| 瑞安市| 囊谦县| 册亨县| 富锦市|