【问题标题】:Excel VBA does not compile - MD5 hash functionExcel VBA 无法编译 - MD5 哈希函数
【发布时间】:2014-09-04 22:08:40
【问题描述】:

现在尝试在我通过互联网找到的 Excel 2011 for Mac 中实现 VBA 模块。以下模块在您看到 As String 的第三行失败:

Option Explicit

Public Function MD5Hash( _
  ByVal strText As String) _
  As String

' Create and return MD5 signature from strText.
' Signature has a length of 32 characters.
'
' 2005-11-21. Cactus Data ApS, CPH.

  Dim cMD5          As New clsMD5
  Dim strSignature  As String

  ' Calculate MD5 hash.
  strSignature = cMD5.MD5(strText)

  ' Return MD5 signature.
  MD5Hash = strSignature

  Set cMD5 = Nothing

End Function

Public Function IsMD5( _
  ByVal strText As String, _
  ByVal strMD5 As String) _
  As Boolean

' Checks if strMD5 is the MD5 signature of strText.
' Returns True if they match.
' Note: strText is case sensitive while strMD5 is not.
'
' 2005-11-21. Cactus Data ApS, CPH.

  Dim booMatch  As Boolean

  booMatch = (StrComp(strMD5, MD5Hash(strText), vbTextCompare) = 0)
  IsMD5 = booMatch

End Function

希望有人可以帮忙,因为这是我第一次玩 VBA。感谢您的帮助!

更新

错误信息文本:

用户自定义类型未定义

【问题讨论】:

  • 您是否尝试过删除续行?还有什么错误?
  • 错误信息是什么?
  • 哎呀抱歉@cronos2546 @Alexandre 错误消息是User-defined type not defined 我实际上已经解决了这个问题,在下面添加解决方案

标签: vba excel excel-2011


【解决方案1】:

我发现了问题,看起来我对 VBA 的接口缺乏了解。原来我的Class Module 没有正确命名。我最终从头开始重建模块,VBA 能够在不同的行上给我一个不同的错误,指向对clsMD5 的引用。这是我修复它的方法:

1) 按alt+F11打开VBA“窗口”

2)使用“属性”窗口编辑类模块的名称,在上面的问题中我需要将名称更改为clsMD5

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-12
    • 1970-01-01
    • 2019-10-22
    • 2011-05-05
    • 1970-01-01
    • 2012-01-30
    相关资源
    最近更新 更多