Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / снова Excel / 2 сообщений из 2, страница 1 из 1
27.12.2007, 11:58
    #35037303
andrew1981
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
снова Excel
При выполнении следующего кода, компилятор выдаёт ошибку №5 (Invalid procedure Call or Argument). Подскажите где ошибка.

With xls.ActiveSheet.QueryTables.Add(MDIForm1.conn, xls.Cells(6, 1), sql1)
.FieldNames = False
.Refresh
End With
...
Рейтинг: 0 / 0
28.12.2007, 09:37
    #35039161
Wasup!
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
снова Excel
Посмотри пример, может быть поможет:
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
Add 'Method (QueryTables Collection) Example

'This example creates a query table based on an ADO recordset. The example preserves 
'the existing column sorting and filtering settings and layout information for backward compatibility.

Dim cnnConnect As ADODB.Connection
Dim rstRecordset As ADODB.Recordset

Set cnnConnect = New ADODB.Connection
cnnConnect.Open "Provider=SQLOLEDB;" & _
    "Data Source=srvdata;" & _
    "User ID=testac;Password=4me2no;"

Set rstRecordset = New ADODB.Recordset
rstRecordset.Open _
    Source:="Select Name, Quantity, Price From Products", _
    ActiveConnection:=cnnConnect, _
    CursorType:=adOpenDynamic, _
    LockType:=adLockReadOnly, _
    Options:=adCmdText

With ActiveSheet.QueryTables.Add( _
        Connection:=rstRecordset, _
        Destination:=Range("A1"))
    .Name = "Contact List"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = True
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod =  0 
    .PreserveColumnInfo = True
    .Refresh BackgroundQuery:=False
End With

'This example imports a fixed width text file into a new query table. 
'The first column in the text file is five characters wide and is imported as text. 
'The second column is four characters wide and is skipped. The remainder of the text
'file is imported into the third column and has the General format applied to it.

Set shFirstQtr = Workbooks( 1 ).Worksheets( 1 ) 
Set qtQtrResults = shFirstQtr.QueryTables.Add( _
    Connection := "TEXT;C:\My Documents\19980331.txt", 
    Destination := shFirstQtr.Cells( 1 , 1 ))
With qtQtrResults
    .TextFileParsingType = xlFixedWidth
    .TextFileFixedColumnWidths := Array( 5 , 4 ) 
    .TextFileColumnDataTypes := _
        Array(xlTextFormat, xlSkipColumn, xlGeneralFormat) 
    .Refresh
End With

'This example creates a new query table on the active worksheet.

sqlstring = "select 96Sales.totals from 96Sales where profit < 5"
connstring = _
    "ODBC;DSN=96SalesData;UID=Rep21;PWD=NUyHwYQI;Database=96Sales"
With ActiveSheet.QueryTables.Add(Connection:=connstring, _
        Destination:=Range("B1"), Sql:=sqlstring)
    .Refresh
End With

Как я понял QueryTables.add ожидает получить не объект Adodb.connection, a рекордсет или текстовую строку.
...
Рейтинг: 0 / 0
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / снова Excel / 2 сообщений из 2, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]