我在下面附带的链接中使用了回复的代码,我有一些问题可以帮助我吗?
VBA Dialog box to select range in different workbook
当我点击refedit框以便能够选择我想要使用的范围时,它会挂起并且当我点击说有一个优先级更高的地方打开另一个窗口时我发出声音但我找不到它
基本上,我要做的是从一个工作簿中复制指定的列并将它们粘贴到我原始工作簿上的工作表中。我知道我的“copyButton_Click()”编码也不对,但我无法在调试中解决这个问题。这就是我所拥有的:
MODULE 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
USERFORM CODE:
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
这是它挂起的地方,不让我点击任何东西。
答案 0 :(得分:1)
您已停用屏幕更新,您需要在Sub extractData()
结束时显示您的用户窗体之前重新激活它:
你有:
ExtractCompareUserForm.Show vbModeless
End If
Application.ScreenUpdating = True
End Sub
切换到:
Application.ScreenUpdating = True
ExtractCompareUserForm.Show vbModal
End If
End Sub