vba - Move data from MS Word to Excel -


i have microsoft word document 400 multiple choice test questions. need put text microsoft excel chart , thought alot easier if able have macro allowed me select text began a. , ends section @ first paragraph object after a..

i tried getting , told use below macro macro not anything. want macro select text only. if in microsoft word manually, hold down ctrl , highlight text begins a. , ends @ first paragraph object.

 sub aselection() ' ' aselection macro '  dim pgh paragraph each pgh in thisdocument.paragraphs pgh if left(.range.text, 2) = "a." , left(right(.range.text, 3), 2) = "a." debug.print .range.text end if end next  end sub 

thisdocument typically refers template document containing executing code. use activedocument instead.

also @assylias said in comment, debug.print code debugging purposes. replace entire line .range.select.

this should work:

sub aselection()      dim o object     dim pgh paragraph      set o = createobject("excel.application")     o.workbooks.open ("e:\aashay data\projects\excel\carton\screen printing.xlsx")     o.activeworkbook.worksheets.add.name = "x"     o.activeworkbook.worksheets("x").activate       each pgh in activedocument.paragraphs         o.activeworkbook.worksheets("x")             debug.print pgh.range.text             if left(pgh.range.text, 2) = "a." , left(right(pgh.range.text, 3), 2) = "a."                 .cells(i, 2).value = pgh.range.text                 = + 1             end if         end     next     o.quit  end sub 


edit: after reviewing , testing lorem ipsum text, realised word vba not allow select multiple discontinuous segments (see ms support article kb288424 more). suppose easiest way export excel debug.print , have edited code accordingly.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -