指令ThisWorkbook.Activate无法正常运行

时间:2019-02-13 20:39:29

标签: excel vba

我有两个工作簿。在第一个中,我调用一个宏来激活另一个宏并从中获取多个数据。然后,它打开一个用户窗体,在其中单击“确定”按钮并在其中运行宏。目前,功能ThisWorkbook.Activate不起作用。 ActiveWorkbook.Name仍然是另一个。但是,当宏停止时,Activeworkbook正确。为什么会发生这种情况。 (我使用的旧版Excel版本没有此问题)

我试图更改屏幕更新。我尝试在激活前后等待一段时间。我试图取消保护床单。我不知道该怎么办。

Private Sub btOK_Click()    
    'Application.ScreenUpdating = True    
    Me.Hide    
    Plan_Inser_Ativ = ValorVariavel("Plan_Inser_Ativ") 'Function to Take a recorded text of Sheet Name (This is working)    
    ThisWorkbook.Unprotect    
    ThisWorkbook.Sheets(Plan_Inser_Ativ).Activate 'I tried to activate the workbook by this method, but this is not working    
    ThisWorkbook.Activate 'I tried to activate by this other method, but this is not working too    
    'Application.Wait (Now + TimeValue("0:00:03"))    
    ThisWorkbook.Activate 'I tried to insist in it to see what happens :-)    
    WB_Ativa = ActiveWorkbook.Name 'The WB_Ativa variable remains with the other Workbook name.    
    Stop 'When the macro stops, if I place the mouse over the ActiveWorkbook.Name statement, it shows that the active Workbook is correct. But before the macro to stop, it was not.`
    ..    
    ..    
    ..    

Print Screen of Macro variable states

0 个答案:

没有答案