Copy contents of HTML to column- error handling VBA Excel -


solved!!! followed advice of jbarker2160 on error resume next solution. refined code made use less resources.

sub project() dim locationarr variant dim long dim g_strvar string dim fake string   locationarr = range("c1:c8877").value  = lbound(locationarr) ubound(locationarr)     fake = (locationarr(i, 1))      g_strvar = importtextfile(fake)      activecell.value = g_strvar activecell.offset(1, 0).select      g_strvar = ""    next end sub  function importtextfile(strfile string) string  on error resume next     open strfile input #1     importtextfile = input$(lof(1), 1)     close #1  end function 

original question how create error handling on process? first time user.

i copying local backup file content intranet csv. have been stumbling around vba build solution. need figure out how handle error.

my current sheet contains list of product sku's, product names, , file path html files populate pages (some of outdated paths).

using vba have place file paths single dimension array. have created loop go through array open file path, copy contents of file, close file, , place contents of file cell.

how handle corrupt/missing file paths?

sub project() dim locationarr variant dim shex object dim long   dim dataobj new msforms.dataobject   dim s string    '    'access clipboard   dataobj.getfromclipboard   s = dataobj.gettext   '   '   ' create array  locationarr = range("c1:c8877").value  '  '  ' access file  set shex = createobject("shell.application")  '  '  '  'loop array = lbound(locationarr) ubound(locationarr)    '    'open file    shex.open (locationarr(i, 1))    '    ' give time open    application.wait (now + timevalue("0:00:01"))    ' handle file    application.sendkeys ("^a")    application.sendkeys ("^c")    application.sendkeys ("%{f4}")    ' give time close application.wait (now + timevalue("0:00:01"))    '    'place clipboard active cell activecell.value = s    '    'move new active cell activecell.offset(1, 0).select    '    ' loop next end sub 

you can put on error resume next @ top of code, can dangerous in circumstances.

i don't foresee problems adding this, if make adjustments or additions code later might want reevaluate.

as stands, worst can expect missing data or bunch of open files.

if paths never valid again can use error handler delete path list.


Popular posts from this blog