excel - 无法在 Excel for MAC 上为 MsSQL 服务器连接重新创建 ODBC
问题描述
我正在编写一个与 mac 兼容的 excel 文件,但我没有 mac,所以我连接到一个 mac 朋友来录制一个宏并进行模拟:我得到了这段代码,创建了一个对我的服务器的简单调用:
Sub Macro1()
'
' Macro1 Macro
'
'
Application.CutCopyMode = False
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"ODBC;DRIVER=SQL Server;SERVER=myserver.database.windows.net;Database=mydb;UID=myuser;" _
, Destination:=Range("$A$1")).QueryTable
.CommandText = Array("select * from mytable")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.RefreshPeriod = False
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
Range("C2").Select
End Sub
把它放到windows上,测试,它,一切正常,
所以我写了以下代码,基本上 100% 相同,带有一个新的查询:
Sub demo__myCall()
Dim sqlstring As String
Dim sLogin As String
Dim connstring As String
Dim destinationCells As Range
Set destinationCells = Sheets("mySheet").Range("A10")
sLogin = "UID=myuser;Pwd=mypawd&123;"
connstring = "ODBC;DRIVER=SQL Server;SERVER=myserver.database.windows.net;Database=mydb;" & sLogin
Dim lo As ListObject
For Each lo In Sheets("mySheet").ListObjects
lo.Delete
Next lo
sqlstring = "select * from myothertable"
With Sheets("INTERNAL").ListObjects.Add(SourceType:=0, Source:=connstring, Destination:=destinationCells).QueryTable
.CommandText = Array(sqlstring)
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells 'xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.RefreshPeriod = False
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With
End Sub
如你所见,difernec 是最小的,
回到mac,测试原来的(Macro1),工作正常,测试第二个(demo__myCall)得到错误“无法完成操作,因为没有安装ODBC控制器”(或类似的东西,因为原始消息是西班牙语)
回到 MAcro 1,工作,回到 demo_myCall,不工作......
有谁能够帮我?
解决方案
推荐阅读
- javascript - 如何在 Javascript 中隐藏元素
- ubuntu - ceph-deploy:错误:无法识别的参数:--data
- sql - Oracle 存储过程不工作 PLS-00306
- git - 重置后如何查找远程分支的git历史记录?
- apache-spark - 如何对随机的 RDD 元素对执行操作?
- c++ - 在实例变量名称旁边使用方括号如何在 C++ 中工作?
- c# - 通过操作/委托对通用对象调用 C# 方法(kotlin 示例)
- python - Python 的 ThreadPoolExecutor 会终止空闲线程吗?
- rust - 如何从`FnMut`闭包中返回捕获的变量,它同时是一个捕获者
- c++ - 无法绘制存储在向量中的 sf::RectangleShape (俄罗斯方块克隆)