Hi im using excel as automation and used OleDB connection and the below is my connection string
“Provider=Microsoft.ACE.OLEDB.12.0; Data Source=“C:\Users\Muthulakshmi\Downloads\Requester_1.xlsx”; Extended Properties=‘Excel 12.0 XML;HDR=YES;ReadOnly=False’”
In the above i have passed the data source as the Excel file path but i want to store the excel path in a variable and then use the variable in the connection string instead of the actual path, but i throws error as the Connection String is a String i cannot pass variables into that. Any Ideas please
Not sure I fully understand your issue. But try putting the connection string into a text file with a key for where the variable is like XXVARXX. Then read the text file and save as variable, then use string replace to replace the key with your variable.
put the script in a text file
“Provider=Microsoft.ACE.OLEDB.12.0; Data Source=“XXVARXX”; Extended Properties=‘Excel 12.0 XML;HDR=YES;ReadOnly=False’”
Read the text file and store as variable.
Replace string activity XXVARXX with Your path.
The result is a variable with the entire connection string.
That is what I am explaining-not sure it works in your use case. I have used this method when I do not want to worry about double quotes or other switch characters.
Make sure you are using the correct double quotes and not the up and down ones. " " not “”
You can use like this.
string connection=“C:\Users\Muthulakshmi\Downloads\Requester_1.xlsx”
“Provider=Microsoft.ACE.OLEDB.12.0; Data Source='”+connection+“'+Extended Properties=Excel 12.0 XML;HDR=YES;ReadOnly=False”