excelnoob123456
New Member
- Joined
- Mar 7, 2015
- Messages
- 39
Hi everyone
I have a spreadsheet with a lot of tabs that looks up to a database and needs refreshing every month. However the command text has to be changed in each tab every month. I have worked out how to change the entire command text to a value in the spreadsheet but it changes the whole value of the command tex, really what I need to be able to do is to just get excel to replace certain text in the commandtext, i.e. If it finds 1456 to 1234 I could change it to something else. This is the code I have to change the values:
I have tried using the following code to get it to replace but it just always gives me an error 'expected: =' I think because it needs an = after the commandtext - I tried doing it with strings as well but I can't work it out - any help greatly appreciated:
I have a spreadsheet with a lot of tabs that looks up to a database and needs refreshing every month. However the command text has to be changed in each tab every month. I have worked out how to change the entire command text to a value in the spreadsheet but it changes the whole value of the command tex, really what I need to be able to do is to just get excel to replace certain text in the commandtext, i.e. If it finds 1456 to 1234 I could change it to something else. This is the code I have to change the values:
Rich (BB code):
ActiveWorkbook.Connections("Database11").OLEDBConnection.CommandText = (Worksheets("Sheet1").Range("list2").Value)
I have tried using the following code to get it to replace but it just always gives me an error 'expected: =' I think because it needs an = after the commandtext - I tried doing it with strings as well but I can't work it out - any help greatly appreciated:
Rich (BB code):
Rich (BB code):
replace(ActiveWorkbook.Connections("Database11").OLEDBConnection.CommandText,"2345",Worksheets("Sheet1").Range("list2").Value)