I have a vba program in excel in my computer (which is using 64bit). My friend can't have all the functions to work (hers is 32bit). What code can I add to make it compatible with the 32bit?
I want to share this excel sheet with many coworkers, so I need it to be compatible with 32bit.
I notice the error happens when calling the function in the worksheet_SelectionChange. I have a code that uses the Days() function.
m = Application.WorksheetFunction.Days(Date, myRange)
Thanks.
Related
When I tried to insert a new sheet, I was given multiple options which I could choose from. One is obviously "Worksheet", another is called "MS Excel 4.0 Macro". So I chose "MS Excel 4.0 Macro", and it looks exactly the same as a new worksheet. I'm just curious what is the difference between a regular worksheet and MS Excel 4.0 Macro sheet?
History
From its first version Excel supported end-user programming of macros (automation of repetitive tasks) and user-defined functions (extension of Excel's built-in function library). In early versions of Excel, these programs were written in a macro language whose statements had formula syntax and resided in the cells of special-purpose macro sheets (stored with file extension .XLM in Windows.) XLM was the default macro language for Excel through Excel 4.0. Beginning with version 5.0 Excel recorded macros in VBA by default but with version 5.0 XLM recording was still allowed as an option. After version 5.0 that option was discontinued. All versions of Excel, including Excel 2010 are capable of running an XLM macro, though Microsoft discourages their use.
https://en.wikipedia.org/wiki/Microsoft_Excel
The purpose of MS Excel 4.0 Macro sheets is to run legacy Excel 4.0 macros. Microsoft replaced Excel 4.0 Macros with VBA in 1993, but they can still be run. Now (almost 30 years later), this is most extensively used by malicious parties (hackers).
For example, you can enter the following into A1:A2:
=EXEC("calc.exe")
=HALT()
Then, to run it (to open the Calculator) you would need to right click A1 and choose Run... -> Run. All the formulas downwards from the clicked cell will be evaluated.
PDF containing the complete Excel 4.0 macro functions reference
Answer.
The old way was to record a macro as a chain of events, without VBA.
My story.
I made heavy use of old-style macros and I have had hundreds of them. When Microsoft shifted macros to VBA they offered no way to convert the old ones, and so I lost all of them at a glance. One of my macros was highly complex and ran like a dream on Mac SE. I regarded it as highly precious in scientific value as it worked using Tritium observations in ground-water aquifers with a huge input function data sheet. It calculated the residence time of ground-water using several mathematical models as well as updating five charts that plotted the output data using introduced by the user for the used models. I saved this macro file to a Windows PC using a complex procedure via the EMU emulations hardware, a modern Mac, and a modern Windows PC, however the file will not run as it was written before the introduction of VBA. It is such a sad loss, and would go as far as considering the loss as criminal.
Please don't delete this story until I have backed it up somewhere. When I have posted it somewhere more appropriate, I promise to delete it.
I've a C# database program and generate an Excel file (*.xlsx) with one sheet using EPPlus. The problem is that least a certain version of Excel does not recalculate the formulas while opening the document. I'm developing the app for somebody else and can tell you next week the exact version of Excel that shows the problem.
I'm not going to show my complete code, but a simple example that demonstrates the problem.
I've copied the example from here and adepted it a bit: EPPlus not caluculating formula output after binding
Here is the code:
using (var pck = new OfficeOpenXml.ExcelPackage())
{
var ws = pck.Workbook.Worksheets.Add("MySheet");
ws.Cells["A3"].Value = 2.3;
ws.Cells["A4"].Value = 10.2;
ws.Cells["A5"].Formula = "=SUM(A3:A4)";
ws.Cells["A5"].Style.Numberformat.Format = "#,##0.00";
ws.Workbook.CalcMode = ExcelCalcMode.Automatic;
pck.SaveAs(new FileInfo(#"c:\users\richard\tmp1.xlsx"));
}
The document opens fine in LibreOffice. It opens also in (the yet unkown) Excel version, but the formula is not recalculated on opening.
I was reluctant to buy a license for MS Office, so I downloaded an Excel viewer first.
ExcelViewer.exe, File version 12.0.4518.1071. This viewer shows the same behaviour: the formula is not calculated.
So, very relunctantly, I purchased Office 365 Home Premium and guess what: this version of Excel DOES recalculate the formulas.
I think it is a bug in the Excel version, not in EPPlus or my code. But is there any workaround to force ALL versions of Excel to recalculate formula's?
And yes, I've tried to read all other relevant postings here, this is not a duplicate.
Many thanks.
I don't think that is likely to be an Excel bug, its would be so fundamental that everyone would know about it. Generating an XL XML file does not calculate formulas. Viewing an Excel file in a viewer does not calculate formulas. Setting a workbook calculation mode to Automatic does not neccessarily mean that Excel will be in Automatic Calculation mode: Calculation mode is an Excel session instance setting taken from the first workbook opened so if Excel is in Manual mode when your workbook is opened it won't calculate. (And BTW I don't see how you expect to successfully create Excel files without being able to test them)
I have a very old VB6 application, we have lost the source code. It can call excel 2003, 2007 to
Launch excel
Insert value to the new sheet cells.
I guess it use com to automate the excel, anyway we lost the source code and cannot contact the programmer.
After we upgrade the office to 2010, it cannot insert value anymore, just a blank sheet ....why?
Do anyone have the same experience as me? old win32 program work on excel 2003/2007 , but don't work on 2010.
Attach screenshot for your reference:
when using excel 2007 , it can fill the value to sheet.
when using excel 2010 , it cannot, and the windbg show some exceptions, how can I troubleshoot it?
Even if you could trace/capture, I don't think that would help you much.
Based on the simplicity of the code, you would be better off remaking it from scratch. If it's something proprietary and very useful, you should probably consider having both versions installed at the same time, which has worked for me just fine.
I need to calculate the error function, Erf(), in my VBA Excel program. I have implemented something like that:
aux_A = -Application.WorksheetFunction.Erf(p)
Previously, in Excel 2007, I install Analysis Toolpak Add-in and it works perfectly but, in Excel 2003 it doesn’t work (and the add-in is installed too).
What’s the problem?
(Please, note that I want to use the result in the VBA code, not in the Excel sheet).
Thank you!
Before Excel 2007, Erf was in the Analysis Toolpack so you had to call the functions directly (Without the WorksheetFunction part)
aux_A = -Erf(p)
Begining with Excel 2007, they move many functions into the WorksheetFunction library and that is why you now have to use WorksheetFunction.Erf(p).
In the VBA Editor, press F2 and search for Erf. You will see that the library and Class is different in versions prior and post 2007.
Doesn't the Erf function take 2 parameters (upper limit, lower limit)?
Add "Analysis Toolpack - VBA" in Add-Ins (Tools -> Add-Ins)
Add reference to atpvbaen.xla in VBA project editor (Tools -> References)
Try:
n = Erf(0.5)
Works for me.
I have a VB6 application running for years. This application always reference Excel 2003 in the past for creating XLS files. Now we would like to use Excel 2010 in place of 2003. So I installed only Excel 2010 on a separate dev computer and load my vb6 project.
When running the app, I got the error where my 'Microsoft Excel 10.0 Object Library' is missing. This is true because only Excel 2010 is installed on this computer and no more Excel 2003.
The problem is that when I would like the correct reference, I didn't find any 'Microsoft Excel 14.0 Object Library' or something equivalent for replacing this reference.
Any suggestion?
Thanks.
Early bound reference are "bound" (excuse the pun) to cause a problem on applications being distributed to users with different Excel versions.
Using late binding and coding for the earliest version of Excel you are willing to support is the solution. For example, if you were supporting Excel 2000, your application would only use methods supported in Excel 2000.
However, if your code was late bound, you could use ambiguous method calls and detect the local version to determine which code to run.
Ex:
Dim excelVersion As Long
Dim xl As Object
' get a reference to Excel.Application maybe from AddinInstance_OnConnection()?
excelVersion = Val(xl.Version)
Select Case excelVersion
Case 11 ' Excel 2003
' Excel 2003-only methods here
' ex: xl.FileSearch
Case 12 ' Excel 2007
' Excel 2007-only methods here
Case 14 ' Excel 2010
' Excel 2010-only methods here
' ex: something with Slicers
End Select
Since the code is late bound (i.e. derived from Object), I can specify methods that are valid only in Excel 2010 and the code will still compile. If the code was early bound to Excel 2003, it wouldn't compile. At runtime I determine the version to decide which methods to use.
You might also consider compiling different versions of your application, if you are using Excel 2010-specific features. Only you would know if that is possible.
Also, and I thought of this after writing this answer, but can't you reference Excel 2010 in your app, and if it is installed on computers with earlier versions of Excel, won't the reference automatically adjust to whatever version of Excel is installed?