如何获得我的查询结果

时间:2018-01-25 15:27:14

标签: mysql excel vba

所以我试图用Excel VBA查询我的SAP软件数据库(显然是Oracle),这样我就可以在工作表中得到我的查询结果。

到目前为止我所做的事情:

Option Explicit 

Private LogonControl As SAPLogonCtrl.SAPLogonControl 
Private ConnexionSAP As SAPLogonCtrl.Connection 
Private TableFactory As SAPTableFactory 

Public Functions As SAPFunctionsOCX.SAPFunctions 

Dim objBAPIControl, objgetaddress As Object 
Dim vLastRow, vRows As Integer 
Dim vcount_add, index_add As Integer 
Dim rng As Range 


Public objaddress, objkunnr As SAPTableFactoryCtrl.Table 
Sub Bouton1_Cliquer() 

Dim dbs As DAO.Database 
Dim rsSQL As DAO.Recordset 
Dim strSQL As String 
Dim sht As Worksheet 

Set sht = ThisWorkbook.ActiveSheet 


Dim retcd        As Boolean 
Dim SilentLogon  As Boolean 


Set LogonControl = CreateObject("SAP.LogonControl.1") 
Set objBAPIControl = CreateObject("SAP.Functions") 
Set ConnexionSAP = LogonControl.NewConnection 


ConnexionSAP.Client = "100" 
ConnexionSAP.ApplicationServer = "x.x.x.x" 
ConnexionSAP.Language = "EN" 
ConnexionSAP.User = "uid" 
ConnexionSAP.Password = "pwd" 
ConnexionSAP.System = "xxx" 
ConnexionSAP.SystemNumber = "00" 
ConnexionSAP.UseSAPLogonIni = False 

SilentLogon = False 
retcd = ConnexionSAP.Logon(0, SilentLogon) 

If retcd = True Then MsgBox "Log OK" 
If retcd <> True Then MsgBox "Logon failed": Exit Sub 


strSQL = "SELECT * FROM INFORMATION_SCHEMA.TABLES" 
Set rsSQL = dbs.OpenRecordset(strSQL, dbOpenSnapshot) 

sht.Cells(1, 2) = "RESULT HERE" 

End Sub

运行此代码会在代码的最后几行显示错误:

  

对象变量或未设置块变量

如何在单元格中获取查询结果(以获取所有数据库表信息)? B1&#39; ?

0 个答案:

没有答案