i want reference different workbooks in code , have used code:
dim basicwb excel.workbook dim basic excel.application set basic = new excel.application set basicwb = basic.workbooks.open("x:\job\masroori\3-042-pms.xlsx")
but problem how can refrence if dont want open each time. used code (without .open) error! : "subscript out of range"
set basicwb = basic.workbooks("x:\job\masroori\3-042-pms.xlsx")
also, dont want activate workbook each time, there way?
taken msdn
site workbooks
property:
"returns workbooks
collection represents open workbooks. read-only."
hence last line of code gives error since file not open. afaik, cannot reference objects within workbook if workbook not open. can access whatever workbook has without activating (so without using .activate
), has open. maybe question of you:
open excel file reading vba without display
if workbook open, can following:
dim wbook excel.workbook, rngtemp range set wbook = workbooks("wbname.xls") wbook ' stuff, no need activate. example: set rngtemp=.sheets(1).usedrange end
i hope helps?
Comments
Post a Comment