excel - Reference Cell from closed Workbook VBA (with error check and relative path) -


going reword pretty poor.

here code got stackoverflow take data cell within closed workbook, works perfect

sub pullvalue() dim path, filename, sheetname, cell

path = "c:\users\admin\desktop\" filename = "book1.xlsm" sheetname = "sheet1" cell = "a1"  range("a2")     .formula = "='" & path & "[" & filename & "]" & sheetname & "'!" & cell & ""     .value = .value end 

end sub

however. trying replace path "c:..." relative link. have tried many forms, i.e. 'thisworkbook.path' nothing seems work, i'm adding code in wrong i'm not vba user.

if has tips it'd appreciated , bonus points if can tell me how ignore errors also. cell return blank if sheetname not exist.

cheers

:)

i see no reason why wouldn't work, however, did remember after thisworkbook.pathto add "\"? mean saying relative paths?


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -