如何通过excel vba为oracle db创建无dsn连接。
这里是我在访问vba中的方式(我有字符串中的变量函数,GetOracleDriver和TNSName,因为每台机器都有自己的)但是在excel中我没有看到oracle驱动程序,当我尝试做手工制作。
Dim NewConnect As String
NewConnect = "ODBC;DRIVER={" & GetOracleDriver & "};SERVER=" & TNSName & ".mycompany.com;UID=myuid;PWD=mypwd;DBQ=" & TNSName & ".mycompany.com;"
谢谢
答案 0 :(得分:3)
我道歉,这是我发布的另一个问题,然后找到答案
并修改了一点
Public Sub ImportData()
Const strSQL_c As String = "SELECT * from NR_CF_CF3_DIR"
Dim strConnection As String
Dim strDBPath As String
strConnection = "ODBC;DRIVER={Oracle in Oracle1};SERVER=mytnsname.mycompany.com;UID=myuid;PWD=mypwd;DBQ=mydbname.mycompany.com"
ActiveWorkbook.Worksheets.Add
ActiveSheet.Name = "QCF3_DIR"
QueryDB strConnection, ActiveSheet.Cells(1, 1), strSQL_c
End Sub
Public Sub QueryDB(ByVal connectionString As String, ByVal target As Excel.Range, ByVal SQL As String)
Dim qt As Excel.QueryTable
Dim ws As Excel.Worksheet
Set ws = target.Parent
Set qt = ws.QueryTables.Add(connectionString, target, SQL)
qt.Refresh BackgroundQuery:=False
End Sub