vba - How to open two documents and copy the text from one to another? -


i have 2 documents.(title.docx , style.docx). need replace text(with italic format) title.docx file text . tried following code. italicizes content of style.docx file instead of italicizing specific text (from title.docx)

sub opendoc()   documents.open filename:="c:\documents , settings\quads\desktop\title.docx", confirmconversions:=true   dim char long dim x long dim count integer   selection.homekey unit:=wdstory, extend:=wdmove x = activedocument.builtindocumentproperties("number of lines") = 0 x char = selection.endkey(unit:=wdline, extend:=wdmove) if (char > 0) selection.homekey unit:=wdstory, extend:=wdmove selection.movedown unit:=wdline, count:=i selection.expand wdline 'msgbox (selection.text) documents.open filename:="c:\documents , settings\quads\desktop\style.docx" selection.find.clearformatting     selection.find.replacement.clearformatting     selection.find.replacement.font.italic = true     selection.find         .text = _             selection.text          .replacement.text = _             selection.text         .forward = true         .wrap = wdfindcontinue         .format = true         .matchcase = false         .matchwholeword = false         .matchwildcards = false         .matchsoundslike = false         .matchallwordforms = false     end     selection.find.execute   end if activedocument.application.selection.movedown unit:=wdline, count:=1 selection.homekey unit:=wdline, extend:=wdmove next 

i need replace style.docx file text(with italic format) title.docx file text.
example: title.docx


this testing text example text sample text 

style.docx


it has text content of other documents , testing text mixed document.

if line has example text in document need italicized.

then last line of document sample text.


expected output: style.docx


it has text content of other documents , this testing text mixed document.

if line has this example text in document need italicized. last line of document this sample text.


open new file in word, add following macro there , save in same folder have both title , style files. assumed each text search in separate paragraph in title file. solution works ok when tried , tested it.

sub opendoc()      dim doctitle document     dim docstyle document     set doctitle = documents.open(filename:=thisdocument.path & "\title.docx", confirmconversions:=true)     set docstyle = documents.open(filename:=thisdocument.path & "\style.docx", confirmconversions:=true)      dim char long     dim x long     dim count integer       dim para paragraph      each para in doctitle.paragraphs          if len(para.range.text) > 1           selection.find.clearformatting         selection.find.replacement.clearformatting         selection.find.replacement.font.italic = true             selection.find                 .text = left(para.range.text, len(para.range.text) - 1)                 .replacement.text = ""                 .forward = true                 .wrap = wdfindcontinue                 .format = true                 .matchcase = false                 .matchwholeword = false                 .matchwildcards = false                 .matchsoundslike = false                 .matchallwordforms = false             end             selection.find.execute replace:=wdreplaceall          end if         activedocument.range(0, 0).select      next para end sub 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -