excel 将32位VBA转换为64位VBA函数时出现问题

pokxtpni  于 2022-12-24  发布在  其他
关注(0)|答案(1)|浏览(343)
Option Explicit
Option Compare Text
Option Base 1

Private Declare PtrSafe Function lstrlen Lib "kernal32" Alias "lstrlenW" ( _
    ByVal lpString As Long) As LongPtr
    
Private Declare PtrSafe Function StrTrim Lib "shlwapi" Alias "StrTrimW" ( _
    ByVal pszSource As Long, _
    ByVal pszTrimChars As Long) As LongPtr
    
Private Function TrimWS(ByVal Text As String) As String
    'unicode safe
    Dim WHITE_SPACE As String
    WHITE_SPACE = " " & vbTab & vbCr & vbLf & Chr(1) & Chr(2) & Chr(3) & Chr(4) & Chr(5) & Chr(6) & Chr(7) & Chr(8) & Chr(9) & Chr(10) & Chr(11) & Chr(12) & Chr(13) & Chr(14) & Chr(15) & Chr(16) & Chr(17) & Chr(18) & Chr(19) & Chr(20) & Chr(21) & Chr(22) & Chr(23) & Chr(24) & Chr(25) & Chr(26) & Chr(27) & Chr(28) & Chr(29) & Chr(30) & Chr(31) & Chr(32) & ChrW(&HA0)

    If StrTrim(StrPtr(Text), StrPtr(WHITE_SPACE)) Then
        TrimWS = Left$(Text, lstrlen(StrPtr(Text)))
    Else
        TrimWS = Text
    End If

End Function

当我切换到64位时,上面的这个函数不起作用。“StrPtr”区域似乎出错了,因为它在64位中不存在。同样,lstrlen似乎也不起作用。它给出了一个不匹配错误。
有谁能给予一些建议,如何转换成64位?
我试着把原来的函数换成LongPtr,我不知道这个函数做什么,但是它会接受所有的字符码并测试它,如果它存在,它会运行lstrlen函数。
我在这件事上碰壁了。

4c8rllxm

4c8rllxm1#

我把longptr安装错了位置,现在工作正常。

Private Declare PtrSafe Function lstrlen Lib "Kernel32" Alias "lstrlenW" ( _
    ByVal lpString As LongPtr) As Long
    
Private Declare PtrSafe Function StrTrim Lib "shlwapi.dll" Alias "StrTrimW" ( _
    ByVal pszSource As LongPtr, _
    ByVal pszTrimChars As LongPtr) As Long

相关问题