csv macro
来源:互联网 发布:被淘宝永久封号怎么办 编辑:程序博客网 时间:2024/06/08 15:46
Option Explicit
Const DB_COLUMN_ROW As Integer = 1
Const DB_DATA_ROW As Integer = 3
Const DB_START_COLUMN As Integer = 1
Sub ExportCsv()
On Error GoTo ERR_LINE
Dim columnIndex As Integer
Dim c As Range
Dim csvHead As String
Dim table As String
columnIndex = DB_START_COLUMN
Set c = Cells(DB_COLUMN_ROW, columnIndex)
table = UCase(c.Comment.Text)
While Trim(c.Value) <> ""
csvHead = csvHead & UCase(Trim(c.Value)) & ","
columnIndex = columnIndex + 1
Set c = Cells(DB_COLUMN_ROW, columnIndex)
Wend
columnIndex = columnIndex - 1
Dim csvNo As Long
Dim csv As String
csv = ThisWorkbook.Path & "\" & table & ".csv"
csvNo = FreeFile
Open csv For Output Access Write As #csvNo
csvHead = Left(csvHead, Len(csvHead) - 1)
Print #csvNo, csvHead
Dim row As Integer
row = DB_DATA_ROW
Set c = Cells(row, DB_START_COLUMN)
Dim i As Integer
Dim dl As String
While Trim(c.Value) <> ""
dl = ""
For i = DB_START_COLUMN To columnIndex
dl = dl & "'" & Trim(Cells(row, i).Value) & "',"
Next i
dl = Left(dl, Len(dl) - 1)
Print #csvNo, dl
row = row + 1
Set c = Cells(row, DB_START_COLUMN)
Wend
Debug.Print csvHead
Debug.Print table
Close #csvNo
MsgBox "done"
Exit Sub
ERR_LINE:
MsgBox Err.Description, vbCritical + vbYesNo, "Error"
If csv <> 0 Then
Close #csvNo
End If
End Sub
Const DB_COLUMN_ROW As Integer = 1
Const DB_DATA_ROW As Integer = 3
Const DB_START_COLUMN As Integer = 1
Sub ExportCsv()
On Error GoTo ERR_LINE
Dim columnIndex As Integer
Dim c As Range
Dim csvHead As String
Dim table As String
columnIndex = DB_START_COLUMN
Set c = Cells(DB_COLUMN_ROW, columnIndex)
table = UCase(c.Comment.Text)
While Trim(c.Value) <> ""
csvHead = csvHead & UCase(Trim(c.Value)) & ","
columnIndex = columnIndex + 1
Set c = Cells(DB_COLUMN_ROW, columnIndex)
Wend
columnIndex = columnIndex - 1
Dim csvNo As Long
Dim csv As String
csv = ThisWorkbook.Path & "\" & table & ".csv"
csvNo = FreeFile
Open csv For Output Access Write As #csvNo
csvHead = Left(csvHead, Len(csvHead) - 1)
Print #csvNo, csvHead
Dim row As Integer
row = DB_DATA_ROW
Set c = Cells(row, DB_START_COLUMN)
Dim i As Integer
Dim dl As String
While Trim(c.Value) <> ""
dl = ""
For i = DB_START_COLUMN To columnIndex
dl = dl & "'" & Trim(Cells(row, i).Value) & "',"
Next i
dl = Left(dl, Len(dl) - 1)
Print #csvNo, dl
row = row + 1
Set c = Cells(row, DB_START_COLUMN)
Wend
Debug.Print csvHead
Debug.Print table
Close #csvNo
MsgBox "done"
Exit Sub
ERR_LINE:
MsgBox Err.Description, vbCritical + vbYesNo, "Error"
If csv <> 0 Then
Close #csvNo
End If
End Sub
0 0
- csv macro
- macro
- macro
- macro
- CSV
- CSV
- csv
- csv
- csv
- CSV
- []csv
- csv
- csv
- CSV
- CSV
- About macro
- Macro Description
- Macro pitfall
- MySQL性能优化的最佳20+条经验
- CSS 伪选择器
- python 单元测试 使用摘要
- Debug PHP with Sublime Text 2 and Xdebug on Ubuntu
- Java 程序员应该了解的 10 个面向对象设计原则
- csv macro
- 快点讲废话刷卡机会
- sqlserver下通用 行转列 函数
- end device 节点失去父节点的处理方法
- SQLite的WAL机制
- Junit4
- ss的sql plus学习笔记(一)
- iOS真机调试证书申请流程
- Android System Service简述