vba - How do I paste into the second column of a table? -


i'm writing macro microsoft word 2007. macro supposed make n x 2 table , insert 1 photo selected every cell. instead, put 2 photos per cell in first column , none in second column.

with application.activedocument         dim mytable word.table     set myrange = activedocument.content     activewindow.view.tablegridlines = true     set mytable = .tables.add(range:=myrange, numrows:=fix((num / 2) + 0.5), numcolumns:=2)         = 1 num         orow = fix((i / 2) + 0.5) '         if (i mod 2) = 1 ocol = 1         if (i mod 2) = 0 ocol = 2         mytable.cell(orow, ocol).select         set pic = .inlineshapes.addpicture(filename:=sdir(i), linktofile:=false, savewithdocument:=true)             pic             .lockaspectratio = msofalse             .height = inchestopoints(2.25)             .width = inchestopoints(3)             end         selection.collapse     next end 

do this:

dim tblcell word.cell 

because it's easier work typed variables, readability , intellisense:

set tblcell = mytable.cell(orow, ocol) set pic = tblcell.range.inlineshapes.addpicture(filename:=sdir(i), linktofile:=false, savewithdocument:=true)         pic         .lockaspectratio = msofalse         .height = inchestopoints(2.25)         .width = inchestopoints(3)         end 

an explanation:

in debugging, did:

i tried replacing "set pic .inlineshapes.addpicture...end with , selection.typetext ("hi")

which should work, since you're working directly selection insert text. had qualified activedocument (you begin code with activedocument)

.inlineshapes.addpicture(... 

still seems odd method used did not work. when did in 2010, puts pictures in first cell only.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -