vba - Saving embedded OLE Object (Excel doc) to file in Excel 2010 vs 2013 -


i trying save embedded ole object (excel doc) current/open workbook location on users pc. ole object template/dashboard gets populated during execution of macro. goal of portion of macro first test if file exists on users c drive. if exist, opens file , sets workbook variable newly opened document. far can tell, works flawlessly between both excel 2010 , excel 2013. in case user not have file saved c drive, macro needs open ole object , save drive. once complete, macro points location , opens file.

the below code works 100% in excel 2013, in excel 2010, macro crashes excel whenever try save file drive. if run macro in break mode, saving works fine, during run-time in cause crash. there possible use of doevents or application.wait here? i'm bit unfamiliar technicalities of saving documents , computer resources.

some things i've noticed:

  1. the crash not generate error code. gives "has stopped responding"
  2. i've tried multiple versions of .saveas fileformat:=52 vs .savecopyas. both methods produce same crash in 2010.
  3. the ole object opens "worksheet in", nice if somehow have open in entirely new workbook. i'm thinking crash related how object opened "worksheet in" rather it's own workbook.

code:

dim uname string dim fname string dim wbk workbook dim sumwb workbook dim cbrwb workbook  set cbrwb = workbooks("previouslyset")      uname = left(environ("appdata"), len(environ("appdata")) - 16) fname = uname & "\otpreport"  & ".xlsm"  if dir(fname) = ""      set oembfile = cbrwb.worksheets("cbrdata").oleobjects("otpreport")     oembfile.verb 0      each wbk in workbooks         if instr(1, wbk.name, "worksheet in", vbtextcompare) > 0 , instr(1, wbk.name, left(cbrwb.name, round(len(cbrwb.name) / 2)), vbtextcompare) > 0             set sumwb = workbooks(wbk.name)         end if     next wbk      sumwb         .activate         .application.displayalerts = false          '==issue exists here==         .savecopyas (fname)          .close     end     set sumwb = nothing     set sumwb = workbooks.open(fname) else:     set sumwb = workbooks.open(fname) end if 

use actual embedded com object instead of default action .verb 0 gives you.

oleobjects expose reference underlying object if being administered com server (it's .object property). in case, since have embedded workbook, it's workbook object other workbook object you'd encounter in vba. should need call .saveas on it:

oembfile.object.saveas fname

then can skip rest of gymnastics related trying find in current excel server.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -