VBA对话框到select范围在不同的工作簿挂了

VBA Dialog box to select range in different workbook hanging up

我使用了下面附上的link中的代码,我遇到了一些问题,你能帮帮我吗?

VBA Dialog box to select range in different workbook

当我点击 refedit 框以便能够 select 我想使用的范围挂断了,当我点击说还有另一个 window 在优先级更高的地方打开,但我找不到它。

基本上,我想做的是从一个工作簿中复制指定的列并将它们粘贴到我原始工作簿的 sheet 中。我知道我的 "copyButton_Click()" 编码也不正确,但我无法深入调试来修复它。这是我拥有的:

模块 1:

  Sub extractData()
    Dim FName As Variant
    Dim wb As Workbook
    Dim destSheet As String
    '
    Application.ScreenUpdating = False
    destSheet = "NewData"
    '
    'Selects and clears data
    Sheets(destSheet).Select
        Range("A2:I12000").Select
        Selection.delete Shift:=xlUp
        Range("A2").Select
    '
    'Prompts user to select updated ILP file to copy data from:
    FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls;*.xlsx;*.xlsm), *.xls;*.xlsx;*.xlsm")
        If FName <> False Then
        Set wb = Workbooks.Open(FName)
    '
    ExtractCompareUserForm.Show vbModeless
    '
        End If

    Application.ScreenUpdating = True

    End Sub

用户代码:

  Private Sub UserForm_Initialize()
        Dim wb As Workbook

    '~~> Get the name of all the workbooks in the combobox
        For Each wb In Application.Workbooks
            ComboBox1.AddItem wb.Name
        Next

        ComboBox1 = ActiveWorkbook.Name
    End Sub

    '~~> This lets you toggle between all open workbooks
    Private Sub Combobox1_Change()
        If ComboBox1 <> "" Then Application.Workbooks(ComboBox1.Text).Activate

        Label1.Caption = "": RefEdit1 = ""
    End Sub

    '~~> This lets you choose the relevant range
    Private Sub RefEdit1_Change()
        Label1.Caption = ""

        If RefEdit1.Value <> "" Then _
        Label1.Caption = "[" & ComboBox1 & "]" & RefEdit1
    End Sub

    Private Sub copyButton_Click()
    Dim addr As String
    '
    addr = RefEdit1.Value
    '
    'Copy Data:
        UserForm1.addr = Selection.Address
        addr.Copy

    End Sub

    Private Sub PasteButton_Click()
    Dim destSheet As String
    '
    Workbooks(2).Close SaveChanges:=False
    '
    '       Now, paste to working workbook:
            Sheets("NewData").Activate
            Range("B2").Select
            ActiveSheet.Paste
            Application.CutCopyMode = False
        Unload Me
        '
    Call CopyData

    End Sub

这是它挂起的地方,不让我点击任何东西。

您已停用屏幕更新,您需要在 Sub extractData() 末尾显示您的用户窗体之前重新激活它:

你有:

    ExtractCompareUserForm.Show vbModeless
End If
Application.ScreenUpdating = True
End Sub

切换到:

    Application.ScreenUpdating = True
    ExtractCompareUserForm.Show vbModal
End If
End Sub