VBA对话框在不同的工作簿中select范围挂起

我使用的是我在下面附加的链接中回复的代码,我有一些问题,你能帮我吗?

VBA对话框在不同的工作簿中select范围

当我点击复制框可以select我想要使用的范围它挂断了,当我点击说有另一个窗口打开某个地方的优先级更高,但我找不到它时,我听到声音。

基本上,我想要做的是从一个工作簿复制指定的列,并将其粘贴到我的原始工作簿中的工作表。 我知道我的“copyButton_Click()”编码是不正确的,但是我不能在debugging中解决这个问题。 这是我有什么:

模块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