Excel 新建图纸-预期变量或过程不是模块

Excel 新建图纸-预期变量或过程不是模块,excel,vba,Excel,Vba,下午好 我想在我的文档中创建重复的工作表。 不幸的是,我得到了一个错误: 预期变量或程序,而非模块 我已在当前工作表中获得组合框列表 其中代码如下所示: Private Sub Cable2_Change() Dim rng As Range Set rng = ActiveSheet.Range("B65") Dim ans As VbMsgBoxResult Select Case rng Case "CFS-PL 107" With Sheets

下午好

我想在我的文档中创建重复的工作表。 不幸的是,我得到了一个错误:

预期变量或程序,而非模块

我已在当前工作表中获得组合框列表

其中代码如下所示:

  Private Sub Cable2_Change()
  Dim rng As Range
  Set rng = ActiveSheet.Range("B65")
  Dim ans As VbMsgBoxResult

  Select Case rng

Case "CFS-PL 107"

        With Sheets("hilti firestopping stores").Range("E5")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Plug").Copy
    ActiveSheet.Range("G18").PasteSpecial
    Selection.Name = "Firestop"

 Case "CFS-PL 132"

        With Sheets("hilti firestopping stores").Range("E6")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Plug").Copy
    ActiveSheet.Range("G19").PasteSpecial
    Selection.Name = "Firestop"

 Case "CFS-PL 158"

        With Sheets("hilti firestopping stores").Range("E7")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Plug").Copy
    ActiveSheet.Range("G20").PasteSpecial
    Selection.Name = "Firestop"

 Case "CFS-PL 202"

        With Sheets("hilti firestopping stores").Range("E8")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Plug").Copy
    ActiveSheet.Range("G21").PasteSpecial
    Selection.Name = "Firestop"

 Case "CFS-CC"

        With Sheets("hilti firestopping stores").Range("E9")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Cable_Collar").Copy
    ActiveSheet.Range("G22").PasteSpecial
    Selection.Name = "Firestop"

 Case "CFS-D 25"

        With Sheets("hilti firestopping stores").Range("E10")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Cable_Disc").Copy
    ActiveSheet.Range("G23").PasteSpecial
    Selection.Name = "Firestop"

 Case "CFS-SL GA1"

        With Sheets("hilti firestopping stores").Range("E11")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Sleeve").Copy
    ActiveSheet.Range("G24").PasteSpecial
    Selection.Name = "Firestop"

 Case "CFS-SL GA2"

        With Sheets("hilti firestopping stores").Range("E12")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Sleeve").Copy
    ActiveSheet.Range("G25").PasteSpecial
    Selection.Name = "Firestop"

 Case "CFS-SL GA3"
        With Sheets("hilti firestopping stores").Range("E13")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Sleeve").Copy
    ActiveSheet.Range("G26").PasteSpecial
    Selection.Name = "Firestop"

 Case "CFS-F FX"
        With Sheets("hilti firestopping stores").Range("E14")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Foam_Blue").Copy
    ActiveSheet.Range("G27").PasteSpecial
    Selection.Name = "Firestop"

 Case "CP 620"
        With Sheets("hilti firestopping stores").Range("E15")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Foam_Red").Copy
    ActiveSheet.Range("G28").PasteSpecial
    Selection.Name = "Firestop"

 Case "CFS-BL"
        With Sheets("hilti firestopping stores").Range("E16")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Block").Copy
    ActiveSheet.Range("G29").PasteSpecial
    Selection.Name = "Firestop"

 Case "CFS-SP SIL"
        With Sheets("hilti firestopping stores").Range("E17")
            .Value = .Value + 1
        End With
    Worksheets("hilti firestopping stores").Shapes("Silicone_Sealant").Copy
    ActiveSheet.Range("G30").PasteSpecial
    Selection.Name = "Firestop"

 Case "Remove"

    ans = MsgBox("Do you want to remove all firestopping elements with their values?", vbQuestion + vbYesNo)
        If ans = vbYes Then
        Sheets("hilti firestopping stores").Range("E5:E17").ClearContents
        Call Firestopshapes
        End If

   End Select
   End Sub
这是我的组合框列表的代码。下面是创建新图纸的另一个代码:

 Sub CablesSheet()

Dim I As Long
Dim xNumber As Integer
Dim xName As String
Dim xActiveSheet As Worksheet
On Error Resume Next
Application.ScreenUpdating = False
Set xActiveSheet = ActiveSheet
xNumber = InputBox("Enter number of times to copy the current sheet")
For I = 1 To xNumber
    xName = ActiveSheet.Name
    xActiveSheet.Copy After:=ActiveWorkbook.Sheets("Cables (Second Floor)")
    ActiveSheet.Name = "Cables (Third Floor)"
  Next
xActiveSheet.Activate
Application.ScreenUpdating = True
End Sub
我在这里找到了一些答案:

我发现,使用
Call
语句并不好

我在代码中使用过一次:

  Call Firestopshapes

如何解决此问题?

您不能使用“工作表”作为代码模块的名称-这会使编译器感到困惑。

您是否使用与某个过程相同的名称命名了代码模块?否。我的代码模块是“工作表”,其中存储了工作表代码。另一个是基于W工作表,在模块外。出错时哪一行突出显示?哪一行抛出错误?@TimWilliams great minds和所有这些:)你是对的!我已经更改了模块名称,现在可以正常工作了!谢谢!