vb6 trying to get old program working with excel 2013 -


i have code program created take data , export excel in vb6 , dont know vb6 started coding in vb.net tell me why isnt working excel 2013 opens closes right away , unsure why.

sub getexcel()          dim myexcel object   ' variable hold reference                               ' microsoft word.          dim excelwasnotrunning boolean   ' flag final release.        ' test see if there copy of microsoft excel running. 10       on error resume next   ' defer error trapping.       ' getobject function called without first argument returns       ' reference instance of application. if application isn't       ' running, error occurs. 20       set myexcel = getobject(, "xlmain") 30       if err.number <> 0 excelwasnotrunning = true 40       err.clear   ' clear err object in case error occurred.        ' check microsoft excel. if microsoft excel running,       ' enter running object table. 50       detectexcel        ' set object variable reference file want see. 60       set myexcel = getobject(app.path & "\test.xls")        ' show microsoft word through application property.       ' show actual window containing file using windows       ' collection of myword object reference.       '   myexcel.application.visible = true       '   myexcel.document(1).visible = true  70        myexcel.show , f1        '//////////////////////////////////////////////        '    manipulations of  file here.        '//////////////////////////////////////////////           ' ...       ' if copy of microsoft excel not running when       ' started, close using application property's quit method.       ' note when try quit microsoft excel,       ' title bar blinks , message displayed asking if       ' want save loaded files. 80       if excelwasnotrunning = true 90          myexcel.application.quit 100      end if  110      set myexcel = nothing   ' release reference                               ' application , spreadsheet. end sub  sub detectexcel()       ' procedure dectects running word , registers it.          const wm_user = 1024          dim hwnd long       ' if excel running api call returns handle. 10       hwnd = findwindow("xlmain", 0) 20       if hwnd = 0   ' 0 means word not running. 30          exit sub 40       else          ' word running use sendmessage api          ' function enter in running object table. 50          sendmessage hwnd, wm_user + 18, 0, 0 60       end if end sub 

even if can direction on how rewrite appreciated.

it's been long time since i've used it, may need address of finer points... but:

first , foremost - rid of on error resume next masks whatever happens next.

this not situation want have errors ignored. capture error, show useful (not debug information , not details can used hacking) user, , resume or return (after cleanup of assigned object variables avoid memory leaks).

then step through code see errors get.

some of things may help:

change specification in getobject "excel.application" i.e.

set myexcel = getobject(, "excel.application") 

instead of myexcel.show may or may not supported, use actual excel objects , methods , properties, instance commented myexcel.application.visible = true works, while question myexcel.document(1).visible = true.

look excel object model details. , never hardcode index - obtain actual reference want , use it.

you can still find articles excel , vb6 on line. use search engine of choice , luck.

beware of impossible - first see if works. can's install vb6 on 64-bit system - not true, there issues getting work. can't interact 64-bit office vb6, not true. maybe can't things - haven't done it, enough know possible things.

consider developing , testing typed objects in vb6. can helpful, make application version independent, need remove object typing before final test , deployment.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -