Листинг 1
Private Sub CommandCreate_Click()
Dim oList As Range ' список параметров таблицы
Dim oCell As Range ' текущая ячейка
Dim sCommand As String ' команда SQL
Dim sParam As String ' параметры
Dim iMode As Integer ' текущий раздел списка
Set oList = Range("$A$1").CurrentRegion
sCommand = "CREATE TABLE "
sParam = "("
iMode = 0
For Each oCell In oList.Resize(oList.Rows.Count, 1)
Select Case oCell.Value
Case "[Table]" ' раздел имени
iMode = 1
Case "[Fields]" ' раздел полей
iMode = 2
Case "[Indexes]" ' раздел индексов
iMode = 3
Case Else
Select Case iMode
Case 1
If UCase(oCell.Value) = "NAME" Then
sCommand = sCommand & oCell.Offset(0, 1).Value
End If
Case 2, 3
If oCell.Value <> "" Then
If Len(sParam) > 1 Then
sParam = sParam & ", "
End If
sParam = sParam & oCell.Value
If oCell.Offset(0, 1).Value <> "" Then
sParam = sParam & " " & _
oCell.Offset(0, 1).Value
End If
End If
End Select
End Select
Next
sParam = sParam & ");"
TextSQL.Value = sCommand & " " & sParam
End Sub