Excel Doesn't Complete Macro after Opening Another Workbook

前端 未结 5 1097
既然无缘
既然无缘 2021-01-17 11:02

I\'m trying to get VBA to fire the commands

sImportFilePath = Application.GetOpenFilename(FileFilter:= _
\"Excel Files (*.xls), *.xls\", Title:=\"Choose The          


        
5条回答
  •  执念已碎
    2021-01-17 11:21

    Temporary solution found on an French forum: use the below ForEachWinDoEvents before activating the workbook of your choice.

    Sub Test()
        Application.ScreenUpdating = False
        Set w1 = Workbooks.Add(xlWBATWorksheet)
        Set w2 = Workbooks.Add(xlWBATWorksheet)
        Set w3 = Workbooks.Add(xlWBATWorksheet)
        Application.ScreenUpdating = True
        ForEachWinDoEvents
        w2.Activate
    End Sub
    
    Sub ForEachWinDoEvents()
    Dim win As Window
      For Each win In Application.Windows
        DoEvents
      Next win
    End Sub
    

提交回复
热议问题