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

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -