zoukankan      html  css  js  c++  java
  • 利用VBA遍历Excel所有sheet的例子

    下面是利用VBA遍历Excel sheet的例子,可以用于Excel的批量处理。

    Sub Insert_CodeString()
    
    Dim fs, ft As Object
    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
    
    Dim Sql As String
        Sql = "truncate table code_string;" & Chr(10)
    Dim line As Integer
    
    Set fs = CreateObject("scripting.filesystemobject")
    Set ft = fs.createtextfile(ThisWorkbook.Path & "" & "Insert_CodeString" & ".sql")
    
    Set xlBook = ThisWorkbook
    
    
    For x = 1 To xlBook.Sheets.Count
    
        Set xlSheet = xlBook.Sheets(x)
        
        If xlSheet.Cells(3, 1) = "代码编号" Then
    
            line = 8
            Sql = Sql & Chr(10) & Chr(10) & "--" & xlSheet.Cells(4, 2) & Chr(10)
            
            Do
                Sql = Sql & "Insert Into CODE_STRING ( CODE_TYPE,CODE_TYPE_DESC,CODE_VALUE,CODE_DESC,CODE_FLAG ) Values ( '" & xlSheet.Cells(3, 2) & "','" & xlSheet.Cells(4, 2) & "','" & xlSheet.Cells(line, 2) & "','" & xlSheet.Cells(line, 3) & "','1');" & Chr(10)
                line = line + 1
            Loop Until Len(xlSheet.Cells(line, 1).Value) = 0
            
        End If
        
    Next x
    
    Sql = Sql & Chr(10) & Chr(10) & "commit;" & Chr(10)
    
    ft.WriteLine (Sql)
    ft.Close
    
    Set ft = Nothing: Set fs = Nothing
    
    End Sub
  • 相关阅读:
    DynamoDB-条件表达式ConditionExpression
    更新表达式updateExpression
    AWS AppSync 的基本语句
    post和get的区别
    图片缩小右移旋转
    加入购物车飞入特效
    c# out参数直接写法
    unity vs 重复打开
    canvas与sprite射线检测
    MySQL语法大全
  • 原文地址:https://www.cnblogs.com/wanggs/p/5039778.html
Copyright © 2011-2022 走看看