Copy Multiples Excel Ranges with VBA to Word as figures -
hi i´m new vba i´m struggling macro i´m trying create. want copy paste figures word file multiples ranges excel.
this code i´ve come with:
sub imagem1() dim objword, objdoc object activewindow.view = xlnormalview worksheets(2).range("a1:o47").select selection.copypicture appearance:=xlscreen, format:=xlpicture set objword = createobject("word.application") set objdoc = objword.documents.add objword.visible = true objword.selection.paste objword.selection.typeparagraph activewindow.view = xlpagebreakpreview end sub sub imagem2() dim objword, objdoc object activewindow.view = xlnormalview worksheets(2).range("u1:ai47").select selection.copypicture appearance:=xlscreen, format:=xlpicture set objword = createobject("word.application") set objdoc = objword.documents.add objword.visible = true objword.selection.paste objword.selection.typeparagraph activewindow.view = xlpagebreakpreview end sub sub imagem3() dim objword, objdoc object worksheets(4).activate activewindow.view = xlnormalview worksheets(4).range("a1:q47").select selection.copypicture appearance:=xlscreen, format:=xlpicture set objword = createobject("word.application") set objdoc = objword.documents.add objword.visible = true objword.selection.paste objword.selection.typeparagraph activewindow.view = xlpagebreakpreview end sub the problem i´m having create 3 different word files 1 image each. know how can code paste 3 images same word file.
i make not creating new word file every time used macro instead copy 3 images opened word file cursor is.
thanks lot help.
tested (changed ranges testing):
sub imagem1() dim objword object, objdoc object, rng object dim wb workbook set wb = activeworkbook 'see if word open on error resume next set objword = getobject(, "word.application") on error goto 0 'not open - create new instance , add document if objword nothing set objword = createobject("word.application") objword.visible = true objword.documents.add end if set objdoc = objword.activedocument set rng = objword.selection wb.windows(1).view = xlnormalview wb.worksheets(1).range("a1:c5").copypicture appearance:=xlscreen, format:=xlpicture rng.paste rng.typeparagraph wb.worksheets(1).range("a7:c12").copypicture appearance:=xlscreen, format:=xlpicture rng.paste rng.typeparagraph wb.worksheets(1).range("a14:c19").copypicture appearance:=xlscreen, format:=xlpicture rng.paste rng.typeparagraph end sub
Comments
Post a Comment