B
Bryan Murtha
I have 725 field names, cut up across 7 files. I need to
import each one of these as a table into a database
diagram in Visio 2003 Professional. Although I have some
experience using VBA for Excel I've never used it for
Visio. Below is the macro I'm using to get the files out
of Excel. If somebody could just give me some pointers on
how I would modify it to import the files back into Visio.
Regards,
Bryan
Sub FlatFiler()
' close the file handle incase it's already open.
Close #1
Close #2
Close #3
Close #4
Close #5
Close #6
Close #7
Open "FlatSQLES" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #1
Open "FlatSQLCS" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #2
Open "FlatSQLCT" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #3
Open "FlatSQLPB" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #4
Open "FlatSQLSS" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #5
Open "FlatSQLSA" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #6
Open "FlatSQLGT" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #7
' get a handle on the worksheet
Set r = Worksheets(1).Range("b2:b726")
' loop through all the rows and seperate them into
different buckets(files)
For i = 1 To r.Rows.Count
' get a handle on the current row
Set thisRow = r.Rows(i)
Select Case thisRow.Cells(1, 2)
Case "ES"
Print #1, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "CS"
Print #2, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "CT"
Print #3, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "PB"
Print #4, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "SS"
Print #5, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "SA"
Print #6, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "GT"
Print #7, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
End Select
Next
' Close the file handles
Close #1
Close #2
Close #3
Close #4
Close #5
Close #6
Close #7
End Sub
Private Function getFieldTypeAndLength(ByVal fieldType,
ByVal fieldLength)
Select Case fieldType
Case "Number": getFieldTypeAndLength = "varchar
(25)"
Case "Y/N": getFieldTypeAndLength = "varchar(4)"
Case "Text": getFieldTypeAndLength = "Varchar(" &
fieldLength & ")"
Case "Date": getFieldTypeAndLength = "varchar(25)"
End Select
End Function
Private Function getFixBoolToChar(ByVal fieldType, ByVal
tableName, ByVal fieldName, ByVal nbtaAlias)
If fieldType = "bit" Then
getFixBoolToChar = Chr(9)
& "dbo.convBoolToYesNo(" & tableName & "." & fieldName
& ")" & Chr(9) & " as " & nbtaAlias & Chr(44)
Else
getFixBoolToChar = Chr(9) & tableName & "." &
fieldName & Chr(9) & " as " & nbtaAlias & Chr(44)
End If
End Function
c
import each one of these as a table into a database
diagram in Visio 2003 Professional. Although I have some
experience using VBA for Excel I've never used it for
Visio. Below is the macro I'm using to get the files out
of Excel. If somebody could just give me some pointers on
how I would modify it to import the files back into Visio.
Regards,
Bryan
Sub FlatFiler()
' close the file handle incase it's already open.
Close #1
Close #2
Close #3
Close #4
Close #5
Close #6
Close #7
Open "FlatSQLES" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #1
Open "FlatSQLCS" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #2
Open "FlatSQLCT" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #3
Open "FlatSQLPB" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #4
Open "FlatSQLSS" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #5
Open "FlatSQLSA" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #6
Open "FlatSQLGT" & Application.Text(Now(), "mmdd")
& ".TXT" For Output As #7
' get a handle on the worksheet
Set r = Worksheets(1).Range("b2:b726")
' loop through all the rows and seperate them into
different buckets(files)
For i = 1 To r.Rows.Count
' get a handle on the current row
Set thisRow = r.Rows(i)
Select Case thisRow.Cells(1, 2)
Case "ES"
Print #1, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "CS"
Print #2, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "CT"
Print #3, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "PB"
Print #4, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "SS"
Print #5, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "SA"
Print #6, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
Case "GT"
Print #7, getFixBoolToChar(thisRow.Cells(1, 7),
thisRow.Cells(1, 5), thisRow.Cells(1, 6), thisRow.Cells
(1, 1))
End Select
Next
' Close the file handles
Close #1
Close #2
Close #3
Close #4
Close #5
Close #6
Close #7
End Sub
Private Function getFieldTypeAndLength(ByVal fieldType,
ByVal fieldLength)
Select Case fieldType
Case "Number": getFieldTypeAndLength = "varchar
(25)"
Case "Y/N": getFieldTypeAndLength = "varchar(4)"
Case "Text": getFieldTypeAndLength = "Varchar(" &
fieldLength & ")"
Case "Date": getFieldTypeAndLength = "varchar(25)"
End Select
End Function
Private Function getFixBoolToChar(ByVal fieldType, ByVal
tableName, ByVal fieldName, ByVal nbtaAlias)
If fieldType = "bit" Then
getFixBoolToChar = Chr(9)
& "dbo.convBoolToYesNo(" & tableName & "." & fieldName
& ")" & Chr(9) & " as " & nbtaAlias & Chr(44)
Else
getFixBoolToChar = Chr(9) & tableName & "." &
fieldName & Chr(9) & " as " & nbtaAlias & Chr(44)
End If
End Function
c