下面是壹個VBA自定義函數。
1,打開壹個工作表;
2.按ALT+F11(或執行工具-宏- VisualBasic編輯器);
3.執行“Insert-Module”,然後雙擊新插入的模塊,將下面的代碼粘貼到右邊的窗口中。
4.如果A1的內容是中國航天六號A,在B1中輸入=hztopy(A1)即可。
函數hztopy(hzpy作為字符串)作為字符串
Dim hzstring作為字符串,pystring作為字符串
Dim hzpysum為整數,hzi為整數,hzpyhex為整數
hzstring = Trim(hzpy)
hzpysum = Len(Trim(hzstring))
pystring = " "
對於hzi = 1到hzpysum
hzpyhex = " & ampH" +十六進制(Asc(Mid(hzstring,hzi,1)))
選擇案例hzpyhex
凱斯& amphb0a 1 To & amp;HB0C4: pystring = pystring + "A "
凱斯& ampHB0C5 To & ampHB2C0: pystring = pystring + "B "
凱斯& amphb2c 1 To & amp;HB4ED: pystring = pystring + "C "
凱斯& ampHB4EE To & ampHB6E9: pystring = pystring + "D "
凱斯& ampHB6EA To & amphb7a 1:py string = py string+" E "
凱斯& ampHB7A2到& ampHB8C0: pystring = pystring + "F "
凱斯& ampHB8C1到& ampHB9FD: pystring = pystring + "G "
凱斯& ampHB9FE To & ampHBBF6: pystring = pystring + "H "
凱斯& ampHBBF7 To & ampHBFA5: pystring = pystring + "J "
凱斯& ampHBFA6 To & ampHC0AB: pystring = pystring + "K "
凱斯& ampHC0AC To & ampHC2E7: pystring = pystring + "L "
凱斯& ampHC2E8 To & ampHC4C2: pystring = pystring + "M "
凱斯& ampHC4C3到& ampHC5B5: pystring = pystring + "N "
凱斯& ampHC5B6 To & ampHC5BD: pystring = pystring + "O "
凱斯& ampHC5BE To & ampHC6D9: pystring = pystring + "P "
凱斯& ampHC6DA To & ampHC8BA: pystring = pystring + "Q "
凱斯& ampHC8BB To & ampHC8F5: pystring = pystring + "R "
凱斯& ampHC8F6到& ampHCBF9: pystring = pystring + "S "
凱斯& ampHCBFA To & ampHCDD9: pystring = pystring + "T "
凱斯& ampHEDC5: pystring = pystring + "T "
凱斯& ampHCDDA To & ampHCEF3: pystring = pystring + "W "
凱斯& ampHCEF4到& ampHD 1b 8:py string = py string+" X "
凱斯& ampHD 1b 9 To & amp;HD4D0: pystring = pystring + "Y "
凱斯& ampHD4D1至& ampHD7F9: pystring = pystring + "Z "
其他情況
pystring = pystring + Mid(hzstring,hzi,1)
結束選擇
然後
hztopy = pystring
結束功能