Excel/VBA: Can't open workbook -
function getproductstatus(adr range) string dim networklocation string, networkpath string, filereference string, srcsheetref string, c_formula string dim sheet_src worksheet, sheet worksheet, wb_src workbook, wb workbook dim sheetname_src string, sheetname string networklocation = activeworkbook.path networkpath = networklocation & "\locations\" sheetname_src = "sheet1" sheetname = "sheet1" set wb_src = thisworkbook set sheet_src = wb_src.sheets(sheetname_src) filereference = networkpath & region_eval & "\productlist.xlsx" workbooks.open filename:=filereference, readonly:=true set wb = workbooks("productlist.xlsx") set sheet = wb.sheets(sheetname) c_formula = application.worksheetfunction.index(sheet.range("$k$2:$k$5000"), application.worksheetfunction.match(sheet_src.range("a" & adr.row), sheet.range("$a$2:$a$5000"), 0)) getproductstatus = c_formula wb.close end function
the following formula works if entered directly in cell:
=index('\\..somepath\locations\[productlist.xlsx]sheet1'!$k$2:$k$5000;match('sheet1'!a2;'\\..somepath\locations\[productlist.xlsx]sheet1'!$a$2:$a$5000;0))
edit:
the question #name error, has been resolved.. evolve worse one.
this function did, @ point, work intended (after #name resolved). between , now, nothing has changed except closing file being asked for. , now, opening file before running function nothing.
how can debug this? why did excel stop opening file?
edit #2: files opened in different instances, apparently, because function work if both files open in same instance. true question now, why doesn't code succeed in opening file "on it's own"?
Comments
Post a Comment