Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6681689
  • 博文数量: 1159
  • 博客积分: 12444
  • 博客等级: 上将
  • 技术积分: 12570
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 21:34
文章分类

全部博文(1159)

文章存档

2016年(126)

2015年(350)

2014年(56)

2013年(91)

2012年(182)

2011年(193)

2010年(138)

2009年(23)

分类: WINDOWS

2012-11-16 23:20:21



汉字中还包含英文字母或数字,英文或数字部分也要返回。
比如:中国航天6号a
返回应为:ZGHT6Ha

下面是一个VBA自定义函数,按ALT+F11,插入模块,在右面窗口中粘贴下面代码。
若A1内容为 中国航天6号a,则在某空白格中输入:=hztopy(A1) 即可

Function hztopy(hzpy As String) As String
  Dim hzstring As String, pystring As String
  Dim hzpysum As Integer, hzi As Integer, hzpyhex As Integer
  hzstring = Trim(hzpy)
  hzpysum = Len(Trim(hzstring))
  pystring = ""
  For hzi = 1 To hzpysum
    hzpyhex = "&H" + Hex(Asc(Mid(hzstring, hzi, 1)))
    Select Case hzpyhex
      Case &HB0A1 To &HB0C4: pystring = pystring + "a"
      Case &HB0C5 To &HB2C0: pystring = pystring + "b"
      Case &HB2C1 To &HB4ED: pystring = pystring + "c"
      Case &HB4EE To &HB6E9: pystring = pystring + "d"
      Case &HB6EA To &HB7A1: pystring = pystring + "e"
      Case &HB7A2 To &HB8C0: pystring = pystring + "f"
      Case &HB8C1 To &HB9FD: pystring = pystring + "g"
      Case &HB9FE To &HBBF6: pystring = pystring + "h"
      Case &HBBF7 To &HBFA5: pystring = pystring + "j"
      Case &HBFA6 To &HC0AB: pystring = pystring + "k"
      Case &HC0AC To &HC2E7: pystring = pystring + "l"
      Case &HC2E8 To &HC4C2: pystring = pystring + "m"
      Case &HC4C3 To &HC5B5: pystring = pystring + "n"
      Case &HC5B6 To &HC5BD: pystring = pystring + "o"
      Case &HC5BE To &HC6D9: pystring = pystring + "p"
      Case &HC6DA To &HC8BA: pystring = pystring + "q"
      Case &HC8BB To &HC8F5: pystring = pystring + "r"
      Case &HC8F6 To &HCBF9: pystring = pystring + "s"
      Case &HCBFA To &HCDD9: pystring = pystring + "t"
      Case &HEDC5: pystring = pystring + "t"
      Case &HCDDA To &HCEF3: pystring = pystring + "w"
      Case &HCEF4 To &HD1B8: pystring = pystring + "x"
      Case &HD1B9 To &HD4D0: pystring = pystring + "y"
      Case &HD4D1 To &HD7F9: pystring = pystring + "z"
      Case Else
        pystring = pystring + Mid(hzstring, hzi, 1)
    End Select
  Next
  hztopy = pystring
End Function

阅读(7038) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~