为了允许具有不同Windows版本的用户运行查询,我实现了一个提示,询问用户是否在Windows 10上。如果用户选择“否”,则会弹出一个消息框,请求一般参数值。不知道为什么会这样。有什么想法吗?
'Prompt user to choose which version of Windows they have
constringopt = MsgBox("Do you have Windows 10?", vbYesNoCancel, "IMAG Data")
If constringopt = vbYes Then
'Import data: Windows 10 version
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DRIVER={Oracle in OraClient11g_home1};UID=XXX;PWD=XXX;SERVER=XXX;DBQ=XXX", _
Destination:=Range("A2"), Sql:=QryStr)
.MaintainConnection = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.Refresh
.Delete
End With
ElseIf constringopt = vbNo Then
'Import data: != Windows 10 version
With ActiveSheet.QueryTables.Add(Connection:="ODBC;DRIVER={Microsoft ODBC for Oracle};UID=XXX;PWD=XXX;SERVER=XXX;", _
Destination:=Range("A2"), Sql:=QryStr)
.MaintainConnection = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.Refresh
.Delete
End With
Else
GoTo Finish_Sub
End If
答案 0 :(得分:0)
使用无参数简化查询并尝试以此方式连接。如果有效,您可以在此处找到答案:Using Parameters with an Oracle ODBC Connection
如果您不想要弹出窗口,可能需要使用单元格来传递参数:请查看此处:Excel: Use a cell value as a parameter for a SQL query