vbscript 将表信息写入范围

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 将表信息写入范围相关的知识,希望对你有一定的参考价值。

Sub WriteTablesInfoToRange(objConn As ADODB.Connection, startCell As Range)
'Description: Writes table and query (View) names and other info to a range
'Inputs:      Connection object; start cell (Range)

Dim adoRecSet As ADODB.Recordset
Dim i         As Long
Dim j         As Long

'   if startCell consists of more then one cell then upper-left is used
    If startCell.Cells.Count > 1 Then startCell = startCell.Cells(1)

    Set adoRecSet = objConn.OpenSchema(adSchemaTables) ', Array(Empty, Empty, Empty, "TABLE")
    
    i = 0
    With adoRecSet
        For j = 0 To .Fields.Count - 1
            startCell.Offset(i, j) = .Fields(j).Name
        Next j
        
        i = 1
        .MoveFirst
        Do While Not .EOF
            For j = 0 To .Fields.Count - 1
                startCell.Offset(i, j) = .Fields(j).Value
            Next j
            .MoveNext
            i = i + 1
        Loop
        .Close
    End With
    Set adoRecSet = Nothing

End Sub

以上是关于vbscript 将表信息写入范围的主要内容,如果未能解决你的问题,请参考以下文章

vbscript 将记录集写入范围

vbscript 将RecordSet列写入范围

vbscript 将记录集写入范围

vbscript 将标题写入范围

如何使用 RPostgreSQL 将表写入 Panoply?

vbscript VBScript将可用磁盘空间写入文件