none
Office 2016 (64-bit): Compile Error - Type mismatch RRS feed

  • Question

  • I have a spreadsheet that was created on earlier versions of Office (32-bit).

    When I installed the new Office 2016 (64-bit) file, I get a VB Error with the script below:

    ====

    'Option Compare Database

    #If Win64 Then
    Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
        "GetUserNameA" (ByVal lpBuffer As String, nSize As LongLong) As LongLong
    #Else
    Private Declare PtrSafe Function apiGetUserName Lib "advapi32.dll" Alias _
        "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    #End If
        
        

    Function fOSUserName() As String
        Dim lngLen As LongLong, lngX As LongLong
        Dim strUserName As String
        
        strUserName = String$(254, 0)
        lngLen = 255
        lngX = apiGetUserName(strUserName, lngLen)
        
        If (lngX > 0) Then
            fOSUserName = Left$(strUserName, lngLen - 1)
        Else
            fOSUserName = vbNullString
        End If
        
    End Function

    =====

    This line is highlighted in yellow:

    Function fOSUserName() As String

    Thursday, September 13, 2018 4:46 PM

All replies