excel - Assorted VBA array iteration woes -


private sub workbook_open()     dim sourcelist(0) workbook     dim pathlist() string     dim n integer     pathlist = split("\data\weaponinfo.csv", ",")      thisworkbook.activate     application.activewindow.visible = false     application.screenupdating = false      n = 0 ubound(pathlist)         workbooks.open filename:=thisworkbook.path & pathlist(n)         set sourcelist(n) = activeworkbook         activewindow.visible = false     next      application.screenupdating = true     workbooks.open filename:=thisworkbook.path & "\heroforge anew 3.5 v7.4.0.1.xlsm", updatelinks:=3     activewindow.visible = true      application.displayalerts = false     n = 0 ubound(sourcelist)         sourcelist(n).close     next     application.displayalerts = true end sub 

the line for n = 0 pathlist.getupperbound(0) throwing "compile error (invalid qualifier) whenever try run macro. highlights pathlist being problem.

also, if cut out loop , have contents run once (replacing pathlist(n) "\data\weaponinfo.csv"), throws "object variable or block variable not set" error on sourcelist(0) = activeworkbook line. doing wrong?

i'm aware loop pointless; it's futureproofing i'm going using macro open multiple data references.

edit: made changes suggested @jeremy below, getting "object variable or block variable not set" error on sourcelist(n).close line.

edit2: fixed loop, again on advice of @jeremy, changing dim sourcelist(1) workbook dim sourcelist(0) workbook

a couple of issues:

  1. in vba, getupperbound method not exist, .net only. change ubound function.

  2. you may run problem sourcelist(0) = activeworkbook. use set keyword when assigning object references.

  3. source not defined in loop. put option explicit @ top of code module force declare variables. save pain in future.

  4. what trying splitting string? 1 value, string passing in.

    private sub workbook_open()        dim sourcelist(1) workbook     dim pathlist() string     dim n integer     pathlist = split("\data\weaponinfo.csv", ",")      thisworkbook.activate     application.activewindow.visible = false     application.screenupdating = false      n = 0 ubound(pathlist)         workbooks.open filename:=thisworkbook.path & pathlist(n)         set sourcelist(0) = activeworkbook     next      activewindow.visible = false      application.screenupdating = true     workbooks.open filename:=thisworkbook.path & "\heroforge anew 3.5 v7.4.0.1.xlsm", updatelinks:=3     activewindow.visible = true      each source in sourcelist         source.close     next end sub 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -