vba - convert .rtf tables to text (comma delimeted) then paste into an excel document -


i have used macro runs through each cell in word table , pastes excel, 1 of documents has 96 pages , take literally 40 mins copy spreadsheet. have found faster if tables converted text (comma delimited) saved .txt file, imported spreadsheet, cannot figure out how write macro or vbscript @ once. ideas??

private sub importwordtable()  dim wddoc object dim wdfilename variant dim tableno integer dim irow long dim icol integer dim resultrow long dim tablestart integer dim tabletot integer  on error resume next  application.screenupdating = false  activesheet.range("a:az").clearcontents  wdfilename = application.getopenfilename("word files (*doc),*.doc", , _ "browse file containing table imported")  if wdfilename = "" exit sub  set wddoc = getobject(wdfilename)   wddoc     tableno = wddoc.tables.count     tabletot = wddoc.tables.count     if tableno = 0         msgbox "this document contains no tables", _         vbexclamation, "import word table"     elseif tableno > 1             tableno = 1      end if      resultrow = 1      tablestart = 1 tabletot         .tables(tablestart)               irow = 1 .rows.count                 icol = 1 .columns.count                    cells(resultrow, icol) = worksheetfunction.clean(.cell(irow, icol).range.text)                     cells(resultrow) = worksheetfunction.clean(.cell(irow).range.text)                 next icol                 resultrow = resultrow + 1             next irow         end         resultrow = resultrow + 1     next tablestart end  set wddoc = nothing  end sub 

try this...

sub importwordtable()  dim wddoc object dim wdfilename variant dim tableno integer dim irow long dim icol integer dim resultrow long dim tablestart integer dim tabletot integer  application.screenupdating = false activesheet.range("a:az").clearcontents  wdfilename = application.getopenfilename("word files (*doc),*.doc", , _             "browse file containing table imported")  if wdfilename = "" exit sub set wddoc = getobject(wdfilename)  wddoc     tableno = wddoc.tables.count     tabletot = wddoc.tables.count      if tableno = 0         msgbox "this document contains no tables", _         vbexclamation, "import word table"     elseif tableno > 1         tableno = 1     end if      tablestart = 1 tabletot         application.statusbar = "processing " & tablestart & "of (" & tabletot & ") tables"         .tables(tablestart).range.copy         resultrow = range("a" & rows.count).end(xlup).offset(2).row         doevents         on error resume next         range("a" & resultrow).pastespecial xlpastevalues         on error goto 0     next tablestart end  set wddoc = nothing application.statusbar = ""  application.screenupdating = true  end sub 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -