vba公共变量与月份的变化

时间:2017-12-19 20:14:45

标签: vba excel-vba variables public excel

我在VBA打招呼,所以我不知道出了什么问题。我的观点是命名一些床单,但我想我可以把它们变成字符串。我做了公共变量,但vba dosent看到它。 somebode可以说出什么是错误的吗?

Public Sub VariableMonths()
    Public one, two, three, DeleteIt As String

    one = "M_11_17"
    two = "M_10_17"
    three = "M_09_17"
    DeleteIt = "M_08_17"
End Sub

然后在这个公共子后面的一部分 - 没有找到变量

Sheets(two).Copy Before:=Sheets(4)
Sheets(two & "( 2)").Select
Sheets(two & "( 2)").Move Before:=Sheets(two)
Sheets(two & "( 2)").Select
Sheets(two & "( 2)").Name = one
Sheets(two).Select
Cells.Select
Selection.Copy

1 个答案:

答案 0 :(得分:1)

在标准模块中:

Dim one As String, two As String, three As String, DeleteIt As String

Sub setupVariables()
    one = "M_11_17"
    two = "M_10_17"
    three = "M_09_17"
    DeleteIt = "M_08_17"
End Sub

Sub MAIN()
    Call setupVariables
    MsgBox three
End Sub

enter image description here