我有一个Excel文件,其中包含由几个数据透视表利用的一系列ODBC DSN连接。刷新数据后,我试图从连接中删除所有密码。我在下面尝试使用此代码将密码更改为空白,并在设置oledbcn连接时遇到运行时错误。有什么想法我做错了吗?
Public Sub RemovePasswordByNamePrefix()
Dim cn As Object
Dim oledbCn As OLEDBConnection
Dim regEx As New RegExp
regEx.Pattern = "Password=[^;]*;"
For Each cn In ThisWorkbook.Connections
Set oledbCn = cn.OLEDBConnection
oledbCn.SavePassword = False
oledbCn.Connection = regEx.Replace(oledbCn.Connection, "")
oledbCn.CommandText = "" 'My app repopulates this after open
Next
End Sub