We have an internally developed tool that can modify the connection strings inside of an Excel 2016 workbook. The tool uses a library provided by Microsoft to access the various parts of an open XML document/file. However, the connection string inside a workbook constructed with Excel 365 appears to store the data source and the command (SQL query) as pointers to a location inside an encrypted string inside the Excel file (.xlsx).
Has anyone been successful in modifying the connection string from an Excel 365 workbook?
Our internal tool uses c# to access the Excel 2016 file.
Related
I am currently creating reporting within excel for lets say 'Non Advanced Users'. I Have successfully created this in and I can execute the stored procedure with parameters typed into excel cells. But when I send this to another user it is saying that it is unable to connect to the data source. Is there a way I could tell excel to use a data source on our network. The connection has SQL Authentication. Basically I want to try and avoid having to create data sources via excel on 100+ machines!!
Yes you can. You can save the connection setting in the excel file itself, and just send out that file. See picture below for step-by-step guide.
Remember to CLEAR (uncheck) the 'Always Use Connection File' in Step 6.
How can I use vba to modify a Powerpivot connection to a csv file? I have an Excel workbook with a Powerpivot model that connects to a csv file. In the Powerpivot window, I can navigate to the Home->Existing Connections and edit the file path as desired. I can't get close to editing this in vba.
I found this link on parameterizing Powerpivot connections.
Unfortunately, I couldn't figure out how to modify to apply to csv file connection rather than database connection.
An alternate approach is described on this page. This approach creates a connection to the data in Excel itself. The connection is then available in Powerpivot. It is critical to not create the connection in Powerpivot bc the author says connections created in Powerpivot cannot be modified by vba.
I can create this connection manually through the
Data->Get External Data->From Text menu option.
I can create the same connection in vba using "Workbooks("myWorkbook.xlsm").Connections.AddFromFile "data.csv". I can manually edit this connection in the Data->Connections->Connections dialog. However, when I try to set this in vba using the WorkbookConnections.TextConnection property, vba says "Object doesn't support this property or method".
The above link focuses on database connections rather than csv file connections. However, it seems possible to set up the csv file with an
Microsoft ACE OLEDB 12.0 connection, but I can't quite grasp it.
There are similar questions on SO that address vba modifying pivot sources (like here:Changing pivot table external data source path with Excel macro).
However, I don't want to bring the data into a table in Excel, I want to connect to it so I can work with it in Powerpivot.
I could probably do this with Power Query, but since I already have the csv in the desired format, I'd rather not have to introduce this additional step.
I'm using Excel 2013 64 bit on Windows 7. Thank you for your help.
I've been playing around with something similar. Haven't succeeded yet, but maybe we can figure it out together...
One thing I've noticed is that it looks like these connections to CSV files aren't actually TextConnections like you'd expect, but rather OLEDBConnections.
EDIT: According to https://goo.gl/x17Nuj, it's just not possible:
Once you modify the connection inside PowerPivot, the link between the Excel and the PowerPivot connections is broken. In fact, you can no longer modify the connection properties in Excel and, if you want to load another table, then you have to use the PowerPivot add-in. Needing to use the add-in means that the option of modifying the connection is no longer available in VBA Because (as you have seen) there is no way to modify the PowerPivot connections using VBA.
(Emphasis is mine)
I was able to modify the file location by setting up the csv file connection as a Microsoft.ACE.OLEDB.12.0 connection. It's actually labelled "Microsoft Office 12.0 Access Database Engine OLE DB Provider" in the Data Connection Wizard. This link helped me figure it out. You need to have "Microsoft ActiveX Data Objects 6.1" added as a reference. Once the connection was created manually, here's the code I used to modify the connection:
Sub editConnection()
With ActiveWorkbook.Connections("myConnectionName").OLEDBConnection
.Connection = "OLEDB;Provider= Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=\\something.com\shared\myDepartment\newDirectory; " & _
"Mode=Read;Extended Properties = ""Text;HDR=Yes;FMT=Delimited;"""
End With
ActiveWorkbook.Connections("myConnectionName").Refresh
End Sub
I didn't figure out how to modify the filename. This also forces the table name in PowerPivot to be the name of the csv file. You can't edit that without breaking the connection.
I have an xlsm file with macros that enable data collection from OLE DB source. I just need to make an import package with it in sql server. But when I'm trying to use import/export wizard or ssis-it shows that it can not deal with .xlsm extentions.
Is there any way to deal with it?
follow this :
1-Create an Excel Connection Manager to refer to ANY other spreadsheet with a "valid" XLS or XLSX extension. (You don't have to save your XLSM file "as" an XLSX.)
2-Select the Excel Connection Manager in your Connection Managers pane.
3-Open the Properties Window (F4).
4-Change the "Server Name" property to the full pathname of your XLSM file.
note: check the file should not be in read only mode
Had the same issue (SQL Server 2008 R2), Rahul's solution worked for me, but I just want to add a couple of things:
Select Excel 2007 in Excel version when creating Excel Connection.
Use SQL Command as Data access mode when editing the Excel Source. Visual Studio crashed for me every time I was trying to use Table or view.
I am using Excel Services in Sharepoint 2010 to inject some data into an Excel xlsm file. This is working fine.
I know that macros will not run on the Sharepoint server, but I want users to be able to download the full workbook after the data injection and have the macros enabled in the full workbook. But, it seems that when Excel Services injects the data, the workbook is always saved with the macros stripped out of the file. Is there any way around this?
How does Excel Services "inject" data? Consider using a data connection in the Excel file instead.
To do that, create a view that shows the data you want and export to Excel. The file now has a data connection to the SharePoint list. You can configure the connection settings and use the data in the spreadsheet. You can hide the sheet with the SharePoint data if it messes up the workbook look.
Or, use the file "injected" with Excel Services as a source file and create a separate file that runs the VBA. Open the injected file and read its data with VBA.
I am using Oracle BI publisher. I created a Excel template report.
once generating the output for that report, I am not able to view the output in excel format. It throws error when I am opening the excel output file "The file you are trying to open, 'name.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?" if I gave yes for this error, the page is opening with no records of output.
I even tried by generating the XML file and loading that file in the excel template, then view, I am able to see the Output. but when uploading the same excel template in the BI application and view the output, it generates the excel output, but throwing the above error and not able to see the output.
The template which i uploaded has XDO_METADATA worksheet page.
I saved my excel template in excel 97-2003 worksheet in .xls format.
My oracle BI publisher desktop version - 11.1.1.7
Excel version- Microsoft excel 2007
Add-ins in excel- BI Publisher template builder for excel - type COM add-in
solver add-in - type excel add-in
We ran into this problem as well. On occasion it would just happen to one report, we would rebuild the excel template and that seemed to resolve the issue. However recently, our whole catalog was an issue. All the excel reports were getting the error, although they ran previously.
Turns out that the temp file on the application server was full. Our admin cleaned it out and restarted the BI service and that seems to have resolved the issue.