excel - Windows(variable).Activate error -


dim filepath string filepath = activeworkbook.path + "\" application.screenupdating = false dim file string dim fullfilepath string file = dir$(filepath & "*example*" & ".*") fullfilepath = filepath & file application.enableevents = false workbooks.open (fullfilepath) windows(file).activate application.enableevents = true 

with above code, quite happily populating filepath, quite happily locating file 'new example.xlsm' , fullfilepath ends correct too.

when gets windows(file).activate subscript out of range error (before gets further)

is obvious? works in 1 of coding examples.

dim filepath string filepath = activeworkbook.path + "\"  application.screenupdating = false  dim file string dim fullfilepath string  file = dir$(filepath & "*example*" & ".*") fullfilepath = filepath & file  application.enableevents = false  dim newwb workbook set newwb = workbooks.open (fullfilepath)  set activewindow = newwb  application.enableevents = true 

i believe little more elegant , easier work with. if declare newwb either static or public variable can use reference on multiple modules or subs. :)


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -