在Excel的VBA里如何定义公共变量?
以下这部份变量代码,我把它放在程序里面执行是正确的,但其它程序又不能使用它,我把它放在公共宣告那里,回到Excel执行时出现编译错误(编译错误显示为:不正确的外部程序),...
以下这部份变量代码,我把它放在程序里面执行是正确的,但其它程序又不能使用它,我把它放在公共宣告那里,回到Excel执行时出现编译错误(编译错误显示为: 不正确的外部程序),如何才能使所有程序都能正常使用它呢?请大师指教,谢谢!
Dim Fer As String
Dim Axal, Axaw, Axsl, Axsw, Aoal, Aoaw, Aoql, Aoqw, r701, r700, Yer, Zer As Double
If Zer > r700 And (Fer = "L" Or Fer = "l") Then
r701 = Zer
ElseIf Yer > r700 And (Fer = "W" Or Fer = "w") Then
r701 = Yer
Else
r701 = r700
End If
Axql = Int((Axsl + Axsw + Aoal) / Aoaw * Aoql - Aoqw)
Axqw = Int((Axsl + Axsw) * (Aoal - Aoaw) / Aoql) 展开
Dim Fer As String
Dim Axal, Axaw, Axsl, Axsw, Aoal, Aoaw, Aoql, Aoqw, r701, r700, Yer, Zer As Double
If Zer > r700 And (Fer = "L" Or Fer = "l") Then
r701 = Zer
ElseIf Yer > r700 And (Fer = "W" Or Fer = "w") Then
r701 = Yer
Else
r701 = r700
End If
Axql = Int((Axsl + Axsw + Aoal) / Aoaw * Aoql - Aoqw)
Axqw = Int((Axsl + Axsw) * (Aoal - Aoaw) / Aoql) 展开
展开全部
你把声明语句以外的代码放在sub ...end sub外面当然会"编译错误: 不正确的外部程序"了
可以先写一个公共过程,public sub 过程名...end sub
例:
public sub abc
Dim Fer As String
Dim Axal, Axaw, Axsl, Axsw, Aoal, Aoaw, Aoql, Aoqw, r701, r700, Yer, Zer As Double
If Zer > r700 And (Fer = "L" Or Fer = "l") Then
r701 = Zer
ElseIf Yer > r700 And (Fer = "W" Or Fer = "w") Then
r701 = Yer
Else
r701 = r700
End If
Axql = Int((Axsl + Axsw + Aoal) / Aoaw * Aoql - Aoqw)
Axqw = Int((Axsl + Axsw) * (Aoal - Aoaw) / Aoql)
end sub
然后在工程内的其它过程或函数中通过过程名调用以上过程
例:
sub aaa
代码段
abc
代码段
end sub
可以先写一个公共过程,public sub 过程名...end sub
例:
public sub abc
Dim Fer As String
Dim Axal, Axaw, Axsl, Axsw, Aoal, Aoaw, Aoql, Aoqw, r701, r700, Yer, Zer As Double
If Zer > r700 And (Fer = "L" Or Fer = "l") Then
r701 = Zer
ElseIf Yer > r700 And (Fer = "W" Or Fer = "w") Then
r701 = Yer
Else
r701 = r700
End If
Axql = Int((Axsl + Axsw + Aoal) / Aoaw * Aoql - Aoqw)
Axqw = Int((Axsl + Axsw) * (Aoal - Aoaw) / Aoql)
end sub
然后在工程内的其它过程或函数中通过过程名调用以上过程
例:
sub aaa
代码段
abc
代码段
end sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询