I'm creating an excel file using EPPlus from a datatable and saving it to a file, all fairly standard. This works without any hassles. However, if I create a vba project, and add any vba code, the resulting .xlsx file is suddenly corrupted. When try and open it with 2013, you get the standard error.
"Excel cannot open the file 'xyz.xlsx' because the file format or file
extension is not valid. Verify that the file extension matches the
format of the file.
If I change the extension to .xls, the file opens ok, and the script runs fine. I'm on the latest beta of Epplus (4.5.0.1). Should I just change the file extension and stick to .xls, or is there something amiss?
ExcelPackage.Workbook.CreateVBAProject()
ExcelPackage.Workbook.CodeModule.Code = "'Script is here"
Dim FInfo as new FileInfo("C:\Myfiles\ThisFile.xlsx")
ExcelPackage.SaveAs(FInfo)
You can not add VBA code to XLSX file format.
Take a look at here
.xlsx:
The default XML-based file format for Excel 2007-2013. Cannot store
Microsoft Visual Basic for Applications (VBA) macro code or Microsoft
Office Excel 4.0 macro sheets (.xlm).
Also take a look at here
to see differences between different formats:
XLSM If you include VBA macros in your XLSX file, you will be asked to
change the file extension to XLSM. Only that way you can save your
macro within the Excel file (there are other file types possible, e.g.
XLSB – but you can’t use XLSX for VBA macros)
Save your file as XLSM and it should work.
Related
I have a large project with Excel VBA files. Planning on moving from the xlsm file format to the xlsb (Excel binary). When I save the xlsm file as an xlsb I get warning.
It displays "abc.xlsm contains features that this version of Microsoft Excel can't save in another file format. Do you want to continue saving in this format and remove these features?"
Didn't know that xlsm can contain stuff that xlsb can't. Would be curious to know what exactly that is.
Anybody got an idea what the problem could be?
I use Display tag in Struts 1.3 to export a table to .xls file.I can export this without any problem and I can open this file with a text editor and view or edit.
<display:setProperty name="export.excel.filename" value="Export.xls"/>
Then created .xls file in Excel 2003 and try to edit it with text editor, but it's binary file.
The file size created with Excel is much bigger comparing to exported file.
Furthermore, When I try to open the exported .xls file in Excel 2013 it gives following popup,
"The file format and extension of 'Export.xls' don't match.
The file could be corrupted or unsafe.
Unless you trust its source ,don't open it.
Do you want to open it anyway ? (Yes/No/Help)"
What is the reason for this?
I found the reason behind this.The exported Excel(.xls) from displaytag is text-based excel and not a POI-based excel.But Excel application creates binary .xls file.
I have programmed macros in Excel and just tried linking the file to Inventor. I am only able to link .xls and .xlsx. The macro-enabled Excel file that I am trying to link can only be saved as a .xlsm. When I try linking it using the all files option (*.*), I am not able to choose the start cell which tells Inventor where to start pulling parameter values from the Excel sheet.
Am I able to link the .xlsm file another way?
Once the file is linked open the parameters menu and find the linked file. right click on that and you should see an option to change the starting cell.
In our Delphi app we automate MS Excel 2007 to generate and save a xls/xlsx file. How should we go about choosing a file format and extension for the generated file?
Hardcoding some values (e.g. xlOpenXMLWorkbook and .xlsx) doesn't work if the user has an older version of Excel installed. Not specifying a format probably works for older versions too (we're checking this right now) but leaves the question what the correct extension is. E.g. using .xls under Excel 2007 results in a XLSX file with wrong extension which leads to complaints when you open it in Excel.
omit extension AND format:
activeworkbook.SaveAs "fred"
will save the file as the appropriate type, and supply the extension too. The file will be fred.xlsx in 2007+ and fred.xls in previous versions.
I am downloading an excel attachment from an email using a tool and converting that file to CSV Using VB Script. The problem I am facing is, after converting the file to CSV, when I try to open the file using notepad, it shows boxes instead of the correct data. But the same file if opened using an excel then it returns the correct data.
But if I create a mew CSV file and open it with notepad I am not facing this problem. kindly help me !!!
Without looking at your script, I would guess that the file is simply renamed to a .csv file - but not actually converted! This way, you would end up seeing the binary data in Notepad.
Try to open the original Excel file in Excel - and there save it as .csv. This will surely work, i.e. you'll see the data in Notepad.
If that does not help, please share your script.