vba - Excel Macro - Windows().Activate not taking value -
the code works following:
windows("contract drilldown (3).xls").activate when utilize :
windows(chr(34) & ddlopenworkbooks.value & chr(34)).activate i get:
runtime error '424': object required
if utilize string variable pass in values i.e.:
dim wbn string wbn = "contract drilldown (3).xls" windows(chr(34) & wbn & chr(34)).activate i get:
run-time error '9': subscript out of range
and if use
wbn = ddlopenworkbooks.value windows(chr(34) & wbn & chr(34)).activate i
runtime error '424': object required
anyone have thought how can pass in ddlopenworkbooks.value in without getting error?
edit - more infook application looks this:
the total code block import info button is:
public sub data_import() windows(ddlopenworkbooks.value).activate columns("a:v").select selection.copy omni_data.activate range("a1").select activesheet.paste omni_data.range("a:z").interior.colorindex = 0 omni_data.range("a:z").font.name = "segoe ui" omni_data.range("a:z").font.name = "segoe ui" 'setting background colour white , changing font end sub the above sub called on click event button.
as test close button has next code:
private sub cmdcancel_click() msgbox (ddlopenworkbooks.value) end end sub which works fine:
updateso have found problem.
as beingness called module didn't know ddlopenworkbooks , pull info from.
the corrected code in sub is:
public sub data_import() windows(frmomnidatamanipulation.ddlopenworkbooks.value).activate columns("a:v").select selection.copy omni_data.activate range("a1").select activesheet.paste omni_data.range("a:z").interior.colorindex = 0 omni_data.range("a:z").font.name = "segoe ui" omni_data.range("a:z").font.name = "segoe ui" 'setting background colour white , changing font end sub this allow me phone call sub.
thanks all!
have tried:
windows(ddlopenworkbooks.value).activate the quotes needed if typing in value. if passing value in other way quotes unnecessary.
update
here steps have taken, , allow me activate selected window no errors.
i created userform combobox named ddlopenworkbooks , 2 buttons.
i hardcoded rowsource of combobox illustration purposes, shouldn't issue here.
my 1st button displays message selected workbooks name ddlopenworkbooks.
here code button
private sub btnmessage_click() msgbox me.ddlopenworkbooks.value end sub here result
my sec button uses selection in ddlopenworkbooks , activates window. here code.
private sub btnactivate_click() windows(me.ddlopenworkbooks.value).activate end sub and here result
final update:
when passing ddlopenworkbooks.value procedure not userform event, you'll need include name of userform.
this line you'll need in procedure correctly value combobox:
windows(frmomnidatamanipulation.ddlopenworkbooks.value).activate excel vba
No comments:
Post a Comment