Making Long variables work in 64 bit AND 32 bit Excel VBA
I agree with @Ken White's answer.
Remark (for some answers):
- You don't ask to convert your 32-bit project into a 64-bit project (which will not work on 32-bit).
- You always NEED to declare the variable type (if you are a good programmer)
You can still use the Long data type in Office 64-bit. It will be compatible for running in 32-bit and 64-bit Office.
But sometimes, you don't have the choice, because some object's properties are not the same data type in 32-bit vs. 64-bit.For instance, if you use ADO:
Dim rstTest As ADODB.Recordset
rstTest.RecordCount
is Long on 32-bit OfficerstTest.RecordCount
is LongLong on 64-bit Office
If you want to store rstTest.RecordCount into a lngCount variable, you MUST declare this variable with LongPtr otherwise it won't work on 32-bit AND 64-bit:
Dim lngCount As LongPtr lngCount = rstTest.RecordCount