VBA "Type Mismatch " Error in Office 64-bit

Zhu, Ligong 240 Reputation points
2025-01-31T13:54:07.7133333+00:00

Hi ,

We have a VBA program that has been working for years. During the test with office 64-bit, we get this error message "Type mismatch" as you can see from the attachment.

User's image

This piece of code is used to open a simple existing text file from local drive:

Dim strFileName As String, strFitDir As String

Dim lngFile As LongPtr 'I also tried LongLong

strFitDir = GetDirectory

strFitDir = "c:\eBB\"

strFileName = strFitDir & "Fix3rdPersonList.txt"

On Error GoTo HandleError

lngFile = FreeFile

Open strFileName For Input As #lngFile

I did modify the code a little bit for Office 64-bit based on this suggestion:

https://learn.microsoft.com/en-us/office/vba/language/concepts/getting-started/64-bit-visual-basic-for-applications-overview

Basically I added "PtrSafe" keyword to declare function and use "LongPtr" or "LongLong" to replace "Long" for 64-bit, otherwise I would get some compile errors.

Please show me how to fix this "Type mismatch" error in text file open line:

Open strFileName For Input As #lngFile

Your help will be greatly appreciated.

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,226 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 119.6K Reputation points
    2025-01-31T14:36:20.65+00:00

    Try this:

    Dim lngFile As Integer
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.