Set RsTable = cnExcel.OpenSchema(adSchemaTables)
Do Until RsTable.EOF
Debug.Print "Table name: " & _
RsTable!TABLE_NAME & vbCr & _
"Table type: " & RsTable!TABLE_TYPE & vbCr
RsTable.MoveNext
Loop
RsTable.Close
问题是:有的EXECL文件没有问题,有的EXECL文件会出现下面的情况:
Table name: 滨洲市$
Table type: TABLETable name: 滨洲市$_
Table type: TABLETable name: 荷泽市$
Table type: TABLETable name: 济南市$
Table type: TABLETable name: 聊城市$
Table type: TABLE
上面出现了两次滨洲市,事实上只有一个"滨洲市"工作表.
急用,谢谢
Do Until RsTable.EOF
Debug.Print "Table name: " & _
RsTable!TABLE_NAME & vbCr & _
"Table type: " & RsTable!TABLE_TYPE & vbCr
RsTable.MoveNext
Loop
RsTable.Close
问题是:有的EXECL文件没有问题,有的EXECL文件会出现下面的情况:
Table name: 滨洲市$
Table type: TABLETable name: 滨洲市$_
Table type: TABLETable name: 荷泽市$
Table type: TABLETable name: 济南市$
Table type: TABLETable name: 聊城市$
Table type: TABLE
上面出现了两次滨洲市,事实上只有一个"滨洲市"工作表.
急用,谢谢
解决方案 »
- SPY++查看一个VC程序出现了点问题
- 如何使用VB模拟拖放文件操作到一个别的程序
- MSchart不想显示图例 用什么代码实现
- 高手指点,为什么同样的语句第一个执行正常,第二个就执行不正常?
- 谁能解决这个问题,送100分喔!
- 如何让文件选择对话框只先目录即可
- 在CAD如何让一个自定义按钮执行我在dll中的程序,请给一个简单的例子。
- 用了ETO_CLIPPED参数的ExtTextOut什么都不显示
- 用VB怎样对LED显示屏进行控制,本单位正准备购进。
- 如何在VB的EXE命令行执行时加参数
- vb出毛病了,有些空间比如grid等在控件栏里显示的图标为白色的了,运行也加载不了
- VB用Excel菜鸟问题请教,高手门帮帮忙...
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(App.Path & "\test.xls") '打开Excel文件
Dim i As Integer
For i = 1 To xlApp.Sheets.Count
Debug.Print xlApp.Sheets(i).Name '打印工作表名
Next
xlApp.Quit
Set xlApp = Nothing
End Sub
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open App.Path & "\test.xls" '打开Excel文件
Dim i As Integer
For i = 1 To xlApp.Sheets.Count
Debug.Print xlApp.Sheets(i).Name '打印工作表名
Next
xlApp.Quit
Set xlApp = Nothing
End Sub
"user32" Alias "SendMessageA" (ByVal hWND As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As LongPrivate Const LB_FINDSTRINGEXACT = &H1A2 '在 ListBox 中精确查找
Private Const CB_FINDSTRINGEXACT = &H158 '在 ComboBox 中精确查找Dim strTmp As String
Set RsTable = cnExcel.OpenSchema(adSchemaTables)
Combo1.Clear
Do Until RsTable.EOF
strTmp = Left(RsTable!TABLE_NAME, InStr(RsTable!TABLE_NAME, "$") - 1)
If SendMessagebyString(Combo1.hWnd, CB_FINDSTRINGEXACT, -1, strTmp) > 0 Then
Combo1.AddItem strTmp
Debug.Print "Table name: " & _
RsTable!TABLE_NAME & vbCr & _
"Table type: " & RsTable!TABLE_TYPE & vbCr
End If
RsTable.MoveNext
Loop
RsTable.Close
If SendMessagebyString(Combo1.hWnd, CB_FINDSTRINGEXACT, -1, strTmp) >= 0 Then
'* Function Name: ToExcel */
'* Input Arguments: */
'* Out Arguments : */
'* : */
'* Description : */
'* Author : by yarno QQ:84115357 */
'* Date : 2005-11-25 */
'***********************************************************************/
Public Function ToExcel()On Error GoTo ErrorHandler Dim exlapp As Excel.Application
Dim exlbook As Excel.Workbook
Set exlapp = CreateObject("Excel.Application")
Set exlbook = exlapp.Workbooks.Add
exlapp.Caption = "数据正在导出......"
exlapp.Visible = True
exlapp.DisplayAlerts = False
Dim exlsheet As Excel.Worksheet
Set exlsheet = exlbook.Worksheets.Add
exlsheet.Activate
Set exlsheet = exlsheet
exlsheet.Name = "我导出的数据"
'设置列宽
exlapp.ActiveSheet.Columns(1).ColumnWidth = 10
exlapp.ActiveSheet.Columns(2).ColumnWidth = 20
StrSql = "你的SQL语句"
Set exl_rs = PubSysCn.Execute(StrSql)
exlsheet.Range("A2").CopyFromRecordset exl_rs
exl_rs.Close
Set exl_rs = Nothing
exlapp.Worksheets("sheet1").Delete
exlapp.Worksheets("sheet2").Delete
exlapp.Worksheets("sheet3").Delete
exlapp.DisplayAlerts = True
exlapp.Caption = "数据导出完毕!!"
exlapp.Visible = True
Set exlapp = Nothing
Set exlbook = Nothing
Set exlsheet = Nothing
Exit Function
ErrorHandler:
MsgBox "EXCEL : " & err.Number & " : " & err.Description
End Function