Excel VBA Run-time error '424': Object Required when trying to copy TextBox -
i'm attempting copy contents of text box 1 workbook
another. have no problem copying cell values first workbook
2nd, object required
error when attempt copy text box. macro
being run workbook containing data want copied. using excel 2007
code:
sub uploaddata() dim xlo new excel.application dim xlw new excel.workbook set xlw = xlo.workbooks.open("c:\myworkbook.xlsx") xlo.worksheets(1).cells(2, 1) = range("d4").value 'copy cell content (this works fine) xlo.worksheets(1).cells(2, 2) = textbox1.text 'this gives me object required error xlw.save xlw.close set xlo = nothing set xlw = nothing end sub
thanks help.
the problem macro once have opened destination workbook (xlw
in code sample), set activeworkbook object , error because textbox1 doesn't exist in specific workbook. resolve issue, define reference object actual workbook before opening other one.
sub uploaddata() dim xlo new excel.application dim xlw new excel.workbook dim mywb excel.workbook set mywb = activeworkbook set xlw = xlo.workbooks.open("c:\myworkbook.xlsx") xlo.worksheets(1).cells(2, 1) = mywb.activesheet.range("d4").value xlo.worksheets(1).cells(2, 2) = mywb.activesheet.textbox1.text xlw.save xlw.close set xlo = nothing set xlw = nothing end sub
if prefer, use mywb.activate
put main workbook active. work if worksheet object. using 1 or depends on want (if there multiple sheets, etc.).
Comments
Post a Comment