Excel VBA - How to check for presence of a table in a different workbook? -


i trying check presence of named ranges in workbooks macro have written iterates through folder full of files. macro have written below works 'normal' named ranges fails when pass function table name named range.

i've searched here , elsewhere on internet why might case, can point out i'm (probably obviously) doing wrong?

any appreciated!

thanks,

adam

public function doesnamedrangeexistinworkbook(byval wb workbook, byval rangename string) boolean  const fn_name string = "doesnamedrangeexistinworkbook" on error goto catch      dim rng range     dim cellcount integer      set rng = wb.names(rangename).referstorange     cellcount = rng.cells.count     doesnamedrangeexistinworkbook = true  finally:     set rng = nothing     exit function  catch:     call errorreport(fn_name, false, err.number, err.description, rangename & " not found in workbook: " & wb.name)     doesnamedrangeexistinworkbook = false     resume  end function 

try (untested)

i assuming table name named range table else have loop through table names check it. let me know if case , update code that.

public function doesnamedrangeexistinworkbook(byval wb workbook, _ byval rangename string) boolean     on error goto catch      dim rng range      on error resume next     set rng = wb.names(rangename)     on error goto 0      if not rng nothing         doesnamedrangeexistinworkbook = true         set rng = nothing     else         doesnamedrangeexistinworkbook = false     end if      exit function catch:     doesnamedrangeexistinworkbook = false end function 

edit

here code checking if particular table exists in workbook or not. using table name check it's existence. again code untested.

public function doestableexist(byval wb workbook, _ byval tblname string) boolean     on error goto catch      doestableexist = false      dim lstobj listobject, ws worksheet      each ws in wb.worksheets         each lstobj in ws.listobjects             if lstobj.name = tblname                 doestableexist = true                 exit function             end if         next     next      exit function catch:     doestableexist = false end function 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -