Use cell value as Workbook Connection value

FergalK

New Member
Joined
Jul 24, 2014
Messages
6
Hi
I'm looking to pass a value from a cell into a VBA query but unsure of the format.
See below code as an example, in the working version of this code, the 3rd line has a specific value for the name of the WorkbookConnection, eg;
With ActiveWorkbook.Connections("MyDataConnection")
What I'm trying to do is use the value in cell B12 instead of MyDataConnection

Appreciate any help!
Thanks

PrivateSub Button_get_wkbook_conn_info_Click()
Dim WorkbookConnectionName As Range
Set WorkbookConnectionName =Worksheets("Lists").Range("B12").Value

With ActiveWorkbook.Connections("& WorkbookConnectionName & ")

Worksheets("Lists").Range("B2").Value = .Name 'Workbook Connection Name
End With
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Code:
Dim connectionValue as String
connectionValue = Cells(12, 2).Value
With ActiveWorkbook.Connection(connectionValue)
etc...etc...
 
Upvote 0
Thanks a lot for that - works just fine! (except for a subsequent problem but that's the subject for a separate post)
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,160
Members
449,209
Latest member
BakerSteve

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top