Excelのデータ接続の接続文字列内のカタログおよびサーバーフィールドを更新するためのユーザー入力を求めるマクロを作成しています。データ接続を更新するVBAマクロ。接続フィールドが変数を受け付けていません
Sub Connection_String()
Dim ConnectionString As String
Dim Catalog As String
Dim Server As String
Catalog = InputBox("Catalog", MsgTitle, "")
Server = InputBox("Server", MsgTitle, "")
ConnectionString = "Provider=MSOLAP;Persist Security Info=True;Initial Catalog=" & Catalog & _
";Data Source=" & Server & ";Auto Synch Period=10000;Cache Ratio=1;MDX Compatibility=1;MDX Unique Name Style=2;" & _
"Safety Options=2;MDX Missing Member Mode=Error;Disable Prefetch Facts=True"
With ActiveWorkbook.Connections("Example Connection").OLEDBConnection
.CommandText = "Example Command Text"
.CommandType = xlCmdCube
.Connection = ConnectionString
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.MaxDrillthroughRecords = 1000
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
.RetrieveInOfficeUILang = True
End With
私はに実行している問題は、私はwith
ステートメント内.Connection = ConnectionString
ラインを参照し、「ランタイムエラー1004アプリケーション定義またはオブジェクト定義のエラー」を得ることです。 .Connection
をConnectionString変数ではなく完全な接続文字列に設定した場合、それは機能します。
は、リンクを頂きありがとうございます。私は以前のものを見ていたが、解決策の1つを見逃しているに違いない。リンクの1つで説明した解決策は、変数に格納された接続文字列に 'OLEDB 'を追加することです。これは私の目的のために機能します。再度、感謝します – randyvelour