Felix Atagong
Active Member
- Joined
- Jun 27, 2003
- Messages
- 359
I have a workbook containing macros that opens a second one (no macros) and does some 'data mining'. The following VBA is used for that (I use this code on dozen of files and it has always worked, except here):
The problem is that most of the time the newly opened workbook is NOT activated (i.e put on top) and thus the rest of the code is executed on the wrong workbook...
If I put in a Msgbox(ActiveWorkbook.Name) 9 out of 10 times the active workbook is the initial one and not the one that was opened by the code...
I tried different solutions as mentioned in the underneath thread
http://www.mrexcel.com/forum/showthread.php?t=348085
but all my attempts failed...
tried replacing Active.Workbook with wb (dim wb as workbook).
tried to wait-a-few-seconds in between code
tried renaming
The page simply refuses to get the macro's focus and it is driving me crazy
Code:
Set WshShell = CreateObject("WScript.Shell")
ChDir (WshShell.SpecialFolders("MyDocuments"))
BladNaam = Application.GetOpenFilename("Excel File, *.xls", , "Excel")
Workbooks.Open FileName:=BladNaam
TabNaam = ActiveSheet.Name
The problem is that most of the time the newly opened workbook is NOT activated (i.e put on top) and thus the rest of the code is executed on the wrong workbook...
If I put in a Msgbox(ActiveWorkbook.Name) 9 out of 10 times the active workbook is the initial one and not the one that was opened by the code...
I tried different solutions as mentioned in the underneath thread
http://www.mrexcel.com/forum/showthread.php?t=348085
but all my attempts failed...
tried replacing Active.Workbook with wb (dim wb as workbook).
tried to wait-a-few-seconds in between code
tried renaming
The page simply refuses to get the macro's focus and it is driving me crazy