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.path
to add "\"? mean saying relative paths?
Comments
Post a Comment