vba - Subscript out of range when copying to cell -


i trying extract data emails using script found online changes run specific information:

option explicit  sub copytoexcel() dim xlapp object dim xlwb object dim xlsheet object dim olitem outlook.mailitem dim vtext variant dim stext string dim vitem variant dim long dim rcount long dim bxstarted boolean const strpath string = "c:\users\rob\documents\excel\exceltest.xlsx" 'the path of workbook  if application.activeexplorer.selection.count = 0     msgbox "no items selected!", vbcritical, "error"     exit sub end if on error resume next set xlapp = getobject(, "excel.application") if err <> 0     application.statusbar = "please wait while excel source opened ... " set xlapp = createobject("excel.application") bxstarted = true end if on error goto 0 'open workbook input data set xlwb = xlapp.workbooks.open(strpath) set xlsheet = xlwb.sheets("sheet1")  'process each selected record rcount = xlsheet.usedrange.rows.count each olitem in application.activeexplorer.selection     stext = olitem.body     vtext = split(stext, chr(13))     'find next empty line of worksheet     rcount = rcount + 1      'check each line of text in message body     = ubound(vtext) 0 step -1         if instr(1, vtext(i), "destination -") > 0             vitem = split(vtext(i), chr(58))             xlsheet.range("a" & rcount) = trim(vitem(1))         end if     next      xlwb.save next olitem xlwb.close savechanges:=true if bxstarted     xlapp.quit end if set xlapp = nothing set xlwb = nothing set xlsheet = nothing set olitem = nothing end sub 

the information have extract emails shown below in bold.

destination state - pennsylvania

destination - pittsburgh

uk airport - london gatwick

airline - united airlines

flight class - premium - £499

depart date - 27/07/2011

return date - 10/08/2011

adults - 2

children - 1

first name - andrew

last name - leakey

telephone - 07785 496123 // number fake

contact email - amdrewsemail@email.org.uk

when run code says "subscript out of range" , debugger says occurring on line.

xlsheet.range("a" & rcount) = trim(vitem(1)) 

replace this:

   vitem = split(vtext(i), chr(58)) 

with this:

  vitem = split(vtext(i),"-") 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -