Without partition version: V1.0:
SubCreatetableddl ()'Create a table statement automatically 'Define line breaks and tabLn =Chr( -) +Chr(Ten) TB=Chr(9) 'defining the Script directory Dim dir as String dir="C:\CREATE_TABLE_DDL" SetFSOE =CreateObject("Scripting.FileSystemObject") IfFsoe.folderexists (dir) =False Then MkDir dir End If 'invoke Script definition SetSQLFILEDDL = FSOE. CreateTextFile ("C:\CREATE_TABLE_DDL\create_table_ddl.sql",True) 'Get table nameTableName =Trim(Cells (1,2). Value)'Get Table CommentsTablecomment =Trim(Cells (1,4). Value)'get created byCreateBy =Trim(Cells (1,6). Value)DimDt as DateDT=Format(Date,"YYYY-MM-DD") 'Get Current dateCreateDate =DT'get the number of rows that a column has usedCount_row_k =[A65536]. End (Xlup). Row'Define SQLSQL ="--Created by:"& CreateBy &Ln SQL= SQL &"--Creation time:"& CreateDate &Ln SQL= SQL &"DROP TABLE IF EXISTS"& TableName &" ;"&Ln SQL= SQL &"CREATE TABLE"& TableName &"(" 'Write Filesqlfileddl.writeline (SQL) fori =3 toCount_row_kIfi = Count_row_k Thencol_name= TB &LCase(Cells (I,2)) &" "&UCase(Cells (I,4)) &"COMMENT '"&Trim(Cells (I,3)) &"'"& Ln &")"sqlfileddl.writeline (col_name)Exit for End Ifcol_name= TB &LCase(Cells (I,2)) &" "&UCase(Cells (I,4)) &"COMMENT '"&Trim(Cells (I,3)) &"',"sqlfileddl.writeline (col_name)NextSqlfileddl.writeline ("COMMENT '"& Tablecomment &"'") MsgBox("Build Succeeded! The build path is:"&dir)End Sub
Excel macro and VBA Practice-build Table statements