PrivateSub CommandButton1_Click()//点击确定按钮执行此过程
If TextBox1.text=""Then//判断是否输入经度
MsgBox "请输入纬度",,"输入"
TextBox1.SetFocus
ExitSubEndIfIf TextBox2.text=""Then//判断是否输入纬度
MsgBox "请输入经度",,"输入"
TextBox2.SetFocus
ExitSubEndIfCalltextCall text2
EndSubPrivateSub CommandButton2_Click()//清空按钮
Call text3
EndSubPrivateSub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)//光标离开纬度文本框时执行此过程
If TextBox1.text=""ThenExitSubEndIf
TextBox1 = Format(TextBox1,"###°##′##″")//将输入的数字转换成度分秒格式
Call text4
On ErrorResumeNextIf a =""ThenElseIf a <0Or a >90Then//判断输入数据是否有误
MsgBox "纬度错误,请重新输入",,"错误"
TextBox1.text=""
TextBox1.SetFocus
StopExitSubEndIfEndIfIf b =""ThenElseIf b <0Or b >60Then
MsgBox "纬度错误,请重新输入",,"错误"
TextBox1.text=""
TextBox1.SetFocus
ExitSubEndIfEndIfIf c =""ThenElseIf c <0Or c >60Then
MsgBox "纬度错误,请重新输入",,"错误"
TextBox1.text=""
TextBox1.SetFocus
EndIfEndIfEndSubPrivateSub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)//光标离开经度文本框时执行此过程
If TextBox2.text=""ThenExitSubEndIf
TextBox2 = Format(TextBox2,"###°##′##″")//将输入的数字转换成度分秒格式
Call text5
On ErrorResumeNextIf d =""ThenElseIf d <0Or d >360Then//判断数据是否有误
MsgBox "经度错误,请重新输入",,"错误"
TextBox2.text=""
TextBox2.SetFocus
ExitSubEndIfEndIfIf e =""ThenElseIf e <0Or e >60Then
MsgBox "经度错误,请重新输入",,"错误"
TextBox2.text=""
TextBox2.SetFocus
ExitSubEndIfEndIfIf f =""ThenElseIf f <0Or f >60Then
MsgBox "经度错误,请重新输入",,"错误"
TextBox2.text=""
TextBox2.SetFocus
EndIfEndIfEndSub
4.插入一个模块,插入代码
Public a, b, c, d,e, f
Public x1 AsLong//定义几个全局变量,用于计算分度编号
Public n1 AsLongPublic x2 AsLongPublic n2 AsLongPublic n3 AsLongPublic n4 AsLongPublic n5 AsLongPublic n6 AsLongPublic n7 AsLongPublic n8 AsLongPublic n9 AsLongPublic n10 AsLongPublic n11 AsLongPublic n12 AsLongSub DoButton(control As IRibbonControl)//当点击菜单地图分幅时执行此过程
UserForm1.Show
EndSubSubtext()//计算分幅编号
x1 = a *3600+ b *60+ c
n1 =Int(x1 /(4*3600))+1
x2 = d *3600+ e *60+ f
n2 =Int(x2 /(6*3600))+30+1
n3 =2-Int((x1Mod (4*3600))/(2*3600))
n4 =Int((x2 Mod(6*3600))/(3*3600))+1
n5 =12-Int((x1Mod (4*3600))/1200)
n6 =Int((x2 Mod(6*3600))/1800)+1
n7 =24-Int((x1Mod (4*3600))/600)
n8 =Int((x2 Mod(6*3600))/900)+1
n9 =48-Int((x1Mod (4*3600))/300)
n10 =Int((x2 Mod(6*3600))/450)+1
n11 =96-Int((x1Mod (4*3600))/150)
n12 =Int((x2 Mod(6*3600))/225)+1EndSubSub text2()//输出最终结果
Dim daihao()As Variant
daihao()=Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S")
UserForm1.TextBox3.text= daihao(n1 -1)& n2
UserForm1.TextBox4.text= UserForm1.TextBox3.text&"B"& Format(CVar(n3),"000")& Format(CVar(n4),"000")
UserForm1.TextBox5= UserForm1.TextBox3.text&"D"& Format(CVar(n5),"000")& Format(CVar(n6),"000")
UserForm1.TextBox6= UserForm1.TextBox3.text&"E"& Format(CVar(n7),"000")& Format(CVar(n8),"000")
UserForm1.TextBox7= UserForm1.TextBox3.text&"F"& Format(CVar(n9),"000")& Format(CVar(n10),"000")
UserForm1.TextBox8= UserForm1.TextBox3.text&"G"& Format(CVar(n11),"000")& Format(CVar(n12),"000")EndSubSub text3()//清空操作
On ErrorResumeNextDim cnt As control
For Each cnt In UserForm1.Controls
cnt.text=""NextEndSubSub text4()//用于提取纬度的度分秒
On ErrorResumeNext
a =Left(UserForm1.TextBox1.text, InStr(UserForm1.TextBox1.text,"°")-1)
b =Mid(UserForm1.TextBox1.text, InStr(UserForm1.TextBox1.text,"°")+1,InStr(UserForm1.TextBox1.text,"′")- InStr(UserForm1.TextBox1.text,"°")-1)
c =Mid(UserForm1.TextBox1.text, InStr(UserForm1.TextBox1.text,"′")+1,InStr(UserForm1.TextBox1.text,"″")- InStr(UserForm1.TextBox1.text,"′")-1)EndSubSub text5()//用于提取经度的度分秒
On ErrorResumeNext
d =Left(UserForm1.TextBox2.text, InStr(UserForm1.TextBox2.text,"°")-1)
e =Mid(UserForm1.TextBox2.text, InStr(UserForm1.TextBox2.text,"°")+1,InStr(UserForm1.TextBox2.text,"′")- InStr(UserForm1.TextBox2.text,"°")-1)
f =Mid(UserForm1.TextBox2.text, InStr(UserForm1.TextBox2.text,"′")+1,InStr(UserForm1.TextBox2.text,"″")- InStr(UserForm1.TextBox2.text,"′")-1)EndSub