excel로 표 작성 문장 생성하기

sub createTable()

    Columns(1).ClearContents

    Dim tableCount As Integer
    Dim fieldCount As Integer
    Dim fields As String
    Dim eachFieldCount As Integer
    Dim dt As String
    Dim f As String
    
    dt = Format(Now, "YYYYMMDDHHMMSS")
    f = ThisWorkbook.Path & "/createTable" & dt & ".txt"
    Open f For Output As #1
    
    tableCount = Int(Sheet4.Cells(1, 2))
    fieldCount = Int(Sheet4.Cells(1, 4))
    MsgBox (" :  " & tableCount & "  " & " " & fieldCount)

    For i = 1 To tableCount
        fields = ""
        eachFieldCount = 0
        For j = 1 To fieldCount
            If Sheet2.Cells() = Sheet1.Cells() Then
                fields = fields + "`" + Trim(Sheet2.Cells()) + "`" + "  " + Trim(Sheet2.Cells()) + "  " + "  comment  " + "'" + Trim(Sheet2.Cells( :comment)) + "'" + "," + Chr(10)
                eachFieldCount = eachFieldCount + 1
            End If
        Next

        fields = Left(fields, Len(fields) - 2)
    
        Print #1, "--  " + CStr(i) + "----" + Sheet1.Cells() + ", " + "----" + CStr(eachFieldCount)
        Print #1, "CREATE  TABLE IF NOT EXISTS " + "`" + " ." + Sheet1.Cells() + "`"
        Print #1, "("
        Print #1, fields
        Print #1, ")" + " comment " + "'" + Trim(Sheet1.Cells( :comment)) + " '"
        Print #1, "ROW FORMAT DELIMITED FIELDS TERMINATED BY ','"
        Print #1, "stored As textfile;"
        Print #1, ""
        
        Sheet3.Cells( ) = eachFieldCount
        
    Next
    
    Close #1

End Sub

좋은 웹페이지 즐겨찾기