Thanks in advance for anyone who reads this and takes the time to respond.
First, I will preface that I am new to VBA and I didn't create the code I am trying to change. With that being said...
We have some spreadsheets that use VBA to create a connection string which is used to connect to a database in SQL Server, and then pull back data in a table using a SQL statement (also embedded in the VBA). This has been working for us just fine so far.
However, we are moving the database which is referenced in the connection string, to a new server. This wouldn't be a problem if we only had a few spreadsheets to update, but unfortunately we have 100's if not 1000's of these to change. Don't even get me started on that topic...
The code to create the connection string looks like this:
Const stCon = "OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=XXXXXX;Data Source=XXXXXX;"
The only thing that is changing is the Data Source, the database name is staying the same so no need to change anything else. As far as I know, the macro that contains this VBA is always called the same thing and is identical in each spreadsheet. It looks like people just did a save as from a base spreadsheet and created multiple versions over time.
I'm looking at tackling this in two ways. The first approach is more of a bandaid quick fix, and that is to create some VBA to change the Data Source in the macro in question in the above connection string statement. The second approach, which would be more future proof, is to figure out a way to have the connection string built so that it isn't hardcoded in every single spreadsheet.
Mind you, I don't know how to do either of these, and that is why I came here. Any suggestions on where to get started would be greatly appreciated. If you need more information to give me suggestions, please ask!
First, I will preface that I am new to VBA and I didn't create the code I am trying to change. With that being said...
We have some spreadsheets that use VBA to create a connection string which is used to connect to a database in SQL Server, and then pull back data in a table using a SQL statement (also embedded in the VBA). This has been working for us just fine so far.
However, we are moving the database which is referenced in the connection string, to a new server. This wouldn't be a problem if we only had a few spreadsheets to update, but unfortunately we have 100's if not 1000's of these to change. Don't even get me started on that topic...
The code to create the connection string looks like this:
Const stCon = "OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=XXXXXX;Data Source=XXXXXX;"
The only thing that is changing is the Data Source, the database name is staying the same so no need to change anything else. As far as I know, the macro that contains this VBA is always called the same thing and is identical in each spreadsheet. It looks like people just did a save as from a base spreadsheet and created multiple versions over time.
I'm looking at tackling this in two ways. The first approach is more of a bandaid quick fix, and that is to create some VBA to change the Data Source in the macro in question in the above connection string statement. The second approach, which would be more future proof, is to figure out a way to have the connection string built so that it isn't hardcoded in every single spreadsheet.
Mind you, I don't know how to do either of these, and that is why I came here. Any suggestions on where to get started would be greatly appreciated. If you need more information to give me suggestions, please ask!