I am trying to open Excel(xlsx) file using FireDAC Delphi Rio 10.3.2. I did the following code:
FDConnection.Params.Clear;
FDConnection.Params.Add('Database=<myfile>');
FDConnection.Params.Add('ODBCDriver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}');
FDConnection.Params.Add('DriverID=ODBC');
FDConnection.Params.Add('ODBCAdvanced=HDR=No');
FDConnection.Open;
I noticed Delphi Rio FireDAC has up to Excel 97-2003
This is the error I am getting with FDConnection for xlsx file:
Can anyone please guide how to achieve Excel (xlsx) file open with FireDAC?
It is easier to use COM Access to Excel as per the following:SO:ADO access to Excel, but if you insist to use FireDAC, the following steps are necessary (checked for Delphi 10.2.3 Tokyo and MS Office 2016, have not tried to dig deeper why FireDAC does not perform these actions):
Define Name for the cells that contain the data to be accessed (with the header) in Formulas->Define Name
Excel must be running and the workbook should be opened (you can use COM to start Excel and make sure that the workbook is opened).
If the workbook was changed by inserting/modifying/deleting data, the workbook has to be saved.
If any of the above is not done, you will see the very meaningful message: External table is not in the expected format.
Because you need COM access to Excel in order to make sure the workbook is open in Excel, I would suggest to use the method 2) from:Excel sheet to Grid
Related
Afternoon all,
I've just upgraded to Office 2013 and I'm trying to get to grips with it.
Since Excel 2003, through 2007 and 2010 I have created and used standard templates for new workbooks and sheets which I store in a specific location. I use the "At startup, open all files in" option in the Advanced Excel options to reference this location so each time a new workbook or sheet is opened, it uses my templates.
In Excel 2013 it works in the first workbook but any workbook after that I open just opens as standard. If I create a new instance of Excel by holding down Alt when I click on it, it also works correctly. It seems as if the change in Excel 2013 to open up workbooks in the same instance which behave as separate instances has the downside of the startup files not being accessed.
Does anyone know how to correct or get around this?
Edit: Same problem if I use the default XLStartup folder
SliderSteve
I've been using ADO to process many Excel .xls and .xlsx workbooks without any problems. Recently I tried to process a .xlsm workbook to load to an Access database. The workbook contains several macros that are run every time a user opens a desktop version of Excel. The macros update "yesterdays" data with "todays" data. Unfortunately when I read the workbook programmatically ADO is returning "yesterdays" data. This means to me that the macros are not running when I open the workbook with ADO. Any suggestions. Hope I don't need to rewrite the code to open an instance of Excel to handle the workbook.
ADO accesses only the data saved in the workbook. Nothing vba (or any other) code does dynamically when the workbook is opened in Excel is available. Excel macros can only run when the workbook is open in the application interface.
Either your process needs to duplicate what the macro(s) are doing in order to update the sheet data or, yes, indeed, you need to first open the workbook in the Excel environment and execute the macros, then SAVE the changes to the workbook.
I am running Excel 2007 under Windows 7 Pro.
I have two add-ins which I have saved as .xla, i.e. as "Excel 97-2003 Add-in".
One is a "Master" add-in, which refers to the other, the "Slave" (through Tools > References)
In VBA, I am able to make a reference the Master add-in from another spreadsheet saved as .xlsm format. It appears to work fine.
Problem:
I change the format of the add-ins from .xla to .xlam (this is non-trivial, involving saving as .xlsm format in between)
I change the reference in the Master .xlam to point to the new Slave .xlam. That works fine, and can be tested.
But when I try to reference the master from the .xlsm spreadsheet, then I get the message "Can't add a reference to the specified file".
If I try again I get a message that just says "400".
Can anyone suggest why it is not possible to add a reference to .xlam from the .xlsm? The code is identical across the two add-in formats. There is no problem in referencing from the Master .xlam to the Slave .xlam . The problem only appears when trying to reference the Master .xlam from the .xlsm spreadsheet.
Both add-ins also refer to other libraries:
Visual Basic for Applications
Microsoft Excel 12.0 Object Library
Microsoft Office 12.0 Object Library
Microsoft Scripting Runtime
Microsoft Forms 2.0 Object Library
I also tried saving the Master as .xslm, and referencing that. It works fine but of course the worksheets of the Master add-in are then visible, which I wanted to avoid.
Thanks for your help.
I created an excel file where I added some buttons that I connected to different macros. I want to send this excel file to a collegue but when he opens this file the button gives an error:
Cannot run the macro "macro-name". The macro may not be available in this workbook or all macros may be disabled.
Is there a way to include or insert macro's inside the excel file?
[I use Microsoft Office Professional Plus 2010]
Found the answer myself, sorry:
Save as.. "Excel Macro-Enabled Workbook (*.xlsm)
I am needing to rename an Excel worksheet that comes to us via FTP. The server the sheet resides on does not have Excel running on it so trying to script it via WSH and vbscript using Excel.Application is out of the question.
Is it possible to rename an Excel worksheet via OLE DB, ODBC or some other mechanism?
You don't need the Excel application to rename an Excel (.xls) file.
Or do you mean to rename a worksheet within a workbook?
Or create your vbscript that uses the Excel object model on a machine where it is available and pass it the full path to the file. Or you could fetch the file via another ftp onto the Excel enabled machine, rename it and ftp it back.
Just out of curiosity: Why do you need to rename the sheet? Is it ok to generate a new Excel file based on the contents of the old one? Can you alter the process that produces or consumes the file somehow?
The question What’s the best .NET library for parsing and generating Excel spreadsheets? seems to contain several pointers.
There are Perl modules for parsing and creating Excel files:Spreadsheet::ParseExcel, Spreadsheet::WriteExcel.