我在UserForm中有一个Button,我编写了一个特定的任务。问题是,当我按下按钮时,窗口将自己切换到代码中指定的工作簿执行分配的工作,并在执行完成后返回到UserForm。 我希望Userform从开始到执行结束都保持在屏幕上而不是切换。 这是代码:
Private Sub CommandButton1_Click()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim hyperlink As String
Dim wbAcro As Workbook
Dim WsEPC As Worksheet
Set wbEPC = Workbooks("" & EPC_Datasheet): wbEPC.Activate
Set WsEPC = wbEPC.Worksheets("Sheet1")
Set wbAcro = Workbooks.Open("C:\EPC AutoTool\Acronyms\Acronyms Details.xlsx")
Dim sh As Worksheet, ws As Worksheet
Dim LstRw As Long, rng As Range, C As Range, Frng As Range, Frng2 As Range
Dim LstR_Template As Integer
Set sh = wbAcro.Sheets("Sheet1")
Set ws = wbEPC.Sheets("Sheet1")
With sh
.Activate
LstRw = .Cells(.Rows.count, "B").End(xlUp).Row
Set rng = .Range("B2:B" & LstRw)
End With
With ws
.Activate
.Application.ScreenUpdating = False
LstR_Template = ActiveSheet.Cells.Find("*", searchorder:=xlByRows, LookIn:=xlValues, searchdirection:=xlPrevious).Row
'*****************
Dim num As String
Dim cf As Range
With .Range("B1:B" & LstR_Template)
Set cf = .Find(what:=Unique_ID, _
lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
num = cf.Address
Range(num).Select
ActiveCell.Offset(0, 1).Select
.Range(Selection, Selection.End(xlDown)).Copy
Range(num).Select
ActiveCell.Offset(0, 0).Select
.Range(Selection, Selection.End(xlDown)).PasteSpecial
End With
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:1)
您可以尝试更改表单的Showmodal属性并查看其影响。