工作表和VBA中UDF的不同结果 [英] Different Results for UDF in Worksheet and VBA

查看:60
本文介绍了工作表和VBA中UDF的不同结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用  StrCmpLogicalW函数在MS Excel中实现Normal,或"Windows文件夹和文件名",或字母数字排序。


我声明了UDF  ; NormalCmp: 


声明函数NormalCmp Lib" shlwapi.dll"别名"StrCmpLogicalW" (ByVal s1 As String,ByVal s2 As String)As Long


这是问题:从工作表调用时:


a9 a81 = normalcmp(A16,B16)


它返回(-1)  - 正确的结果,"a9"<""" a81"


但使用VBA时:



子测试()


     MsgBox NormalCmp(" a9"," a81")


End Sub

它会返回1,但是它会使用相同的函数和参数。

解决方案

Hello Ander,


 


欢迎来到MSDN论坛。


< p style ="margin:0in 0in 0pt">  


根据您的描述,它应该是VB6问题。


对于Visual Basic 6的问题,您也可以尝试:


http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/6a0719fe-14af-47f7-9f51-a8ea2b9c8d6b < span style ="font-size:12pt">


如果是VBA程序 ,您也可以尝试队列:


http:// social.msdn.microsoft.com/Forums/en-US/vstsappverifier/threads



 


谢谢你您的理解和支持。


 


< span style ="font-family:Calibri">最好的问候,



I'm trying to implement Normal, or "Windows folder and filename", or alphanumerical sorting in MS Excel by using StrCmpLogicalW function.

I declared UDF NormalCmp: 

Declare Function NormalCmp Lib "shlwapi.dll" Alias "StrCmpLogicalW" (ByVal s1 As String, ByVal s2 As String) As Long

Here is the problem: when called from Worksheet:

a9 a81 =normalcmp(A16,B16)

it returns (-1)  - right result, "a9"<"a81"

but when using VBA:

Sub test()

    MsgBox NormalCmp("a9", "a81")

End Sub

it returns 1, although it uses the same function and parameters.

解决方案

Hello Ander,

 

Welcome to MSDN forum.

 

Based on your description, it should be a VB6 issue.

For Visual Basic 6 questions, you could also try:

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/6a0719fe-14af-47f7-9f51-a8ea2b9c8d6b

If it is a VBA program, you could also try the queue:

http://social.msdn.microsoft.com/Forums/en-US/vstsappverifier/threads

 

Thank you for your understanding and support.

 

Best Regards,


这篇关于工作表和VBA中UDF的不同结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆