在这里我只想要它,以便如果单击另一个复选框,它将运行 Else 块中的代码。Duplicate Declaration in Current Scope
代码运行得很好,只有 If Choice1 is True 块,但是当我添加 Else 块时会出现错误:
Private Sub CommandButton1_Click()
If Choice1.Value = True Then
Dim filename As String
filename = ThisWorkbook.Path & Application.PathSeparator & "somefile.xlsm"
Dim wk As Workbook
Set wk = Workbooks.Open(filename, ReadOnly:=True)
Dim rgSource As Range, rgDestination As Range
' set rgsource = [workbook].[worksheet].[range]
Set rgSource = ThisWorkbook**strong text**.Worksheets("Source").**Range("A1:B7")**
Set rgDestination = ThisWorkbook.Worksheets("Destination").Range("A1")
rgSource.Copy
rgDestination.PasteSpecial xlPasteValues
wk.Close saveChanges:=False
ElseIf Choice2.Value = True Then
Dim filename As String
filename = ThisWorkbook.Path & Application.PathSeparator & "Otherfile.xlsm"
Dim wk As Workbook
Set wk = Workbooks.Open(filename, ReadOnly:=True)
Dim rgSource As Range, rgDestination As Range
' set rgsource = [workbook].[worksheet].[range]
Set rgSource = wk.Worksheets("Sheet1").**Range("E1:F7")**
Set rgDestination = ThisWorkbook.Worksheets("Destination").Range("A1")
rgSource.Copy
rgDestination.PasteSpecial xlPasteValues
wk.Close saveChanges:=False
ElseIf Choice3.Value = True Then ...etc.
End If
End Sub