none
關於VB2005在Excel巨集下的程式碼錯誤問題 RRS feed

  • 問題

  • Code Snippet

    Public myApp, mySheets, myRange, myQueryTable As Object

              myApp = CreateObject("Excel.Application")           

              mySheets = myApp.sheets
              myRange = myApp.range
              myQueryTable = myApp.QueryTable

     

                With mySheets.ListObjects.Add(SourceType:=0, Source:=Array( _
                    "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Documents and Settings\Administrator\桌面\VB2005\Visual Basic 2005 程" _
                    , _
                    "式設計經典(第二版)\資料庫連結Web\PERSONDB.MDB;Mode=Share Deny None;Extended Properties="""";Jet OLEDB:System database="""";Jet OLEDB:Registry Pat" _
                    , _
                    "h="""";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transac" _
                    , _
                    "tions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don" _
                    , _
                    "'t Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
                    ), Destination:=myRange("$A$1")).myQueryTable
                    .CommandType = 3
                    .CommandText = Array("PERSON")
                    .RowNumbers = False
                    .FillAdjacentFormulas = False
                    .PreserveFormatting = True
                    .RefreshOnFileOpen = False
                    .BackgroundQuery = True
                    .RefreshStyle = 1
                    .SavePassword = False
                    .SaveData = True
                    .AdjustColumnWidth = True
                    .RefreshPeriod = 0
                    .PreserveColumnInfo = True
                    .SourceConnectionFile = _
                    "C:\Documents and Settings\Administrator\My Documents\我的資料來源\(預設) PERSON.odc"
                    .ListObject.DisplayName = "表格_預設__PERSON"
                    .Refresh(BackgroundQuery:=False)
                End With

     

     

     

     

    錯誤 1 'Array' 為型別,無法當成運算式使用。

    我想請問上面紅色部分的這個錯誤要如何來排除呢?(這是我由Excel巨集那邊的"資料庫連結"複製過來的)

    我查詢MSDN的範例,也是寫Array。

     

     

    2008年2月24日 下午 04:17

解答

  • VBNET 沒有 Array 函數,物件類別 Array 用法跟 VBA 不同。

     

    替代語法:

    .CommandText = New Object(){"PERSON"}

    .CommandText = New String(){"PERSON"}

    2008年2月24日 下午 11:21
    版主