Pasting text into table loses character formatting and changes font size


word 2010:

have macro cuts text document , places in cell of table. first 2 words of text have bold character formatting.

when macro pastes text table, half time, bold character formatting lost. other half of time, formatting retained.
this font size changed, 11 10.


i'm pasting using selection.pasteandformat (wdformatoriginalformatting)

clues why might happen?

sub phototable()
selection
.characters(1).case = wdtitlesentence
.expand unit:=wdsentence
.expand unit:=wdparagraph
.paragraphs.outdent
.cut
'.style = activedocument.styles("normal")
end with
activedocument.tables.add range:=selection.range, numrows:=1, numcolumns:= _
2, defaulttablebehavior:=wdword9tablebehavior, autofitbehavior:= _
wdautofitfixed

selection.tables(1)
.columns.preferredwidth = inchestopoints(3.5)
.autoformat format:=wdtableformatgrid1, applyborders:=false, _
applyshading:=false, applyfont:=false, applycolor:=false, _
applyheadingrows:=false, applylastrow:=false, applyfirstcolumn:= _
false, applylastcolumn:=false, autofit:=false
end with


selection.tables(1)
.borders(wdborderleft).linestyle = wdlinestylenone
.borders(wdborderright).linestyle = wdlinestylenone
.borders(wdbordertop).linestyle = wdlinestylenone
.borders(wdborderbottom).linestyle = wdlinestylenone
.borders(wdbordervertical).linestyle = wdlinestylenone
.borders(wdborderdiagonaldown).linestyle = wdlinestylenone
.borders(wdborderdiagonalup).linestyle = wdlinestylenone
.borders.shadow = false
'set width of row, cell
.cell(1, 1).setwidth _
columnwidth:=inchestopoints(3.5), _
rulerstyle:=wdadjustnone
.cell(1, 2).setwidth _
columnwidth:=inchestopoints(3.5), _
rulerstyle:=wdadjustnone


end with
selection.pasteandformat (wdformatoriginalformatting)
end sub

try using following instead

dim tbl table
selection
    .characters(1).case = wdtitlesentence
    .paragraphs(1).outdent
    set tbl = .converttotable(, 1, 2)
end
tbl.columns.preferredwidth = inchestopoints(3.5)


-- hope helps.

doug robbins - word mvp,
dkr[atsymbol]mvps[dot]org
posted via community bridge

"mcramer" wrote in message news:4f10baa4-fe0c-4f11-bf37-f580641552a3@communitybridge.codeplex.com...


word 2010:

i have macro cuts text document , places in cell of table. first 2 words of text have bold character formatting.

when macro pastes text table, half time, bold character formatting lost. other half of time, formatting retained.
font size changed, 11 10.


i'm pasting using selection.pasteandformat (wdformatoriginalformatting)

any clues why might happen?

sub phototable()
selection
characters(1).case = wdtitlesentence
expand unit:=wdsentence
expand unit:=wdparagraph
paragraphs.outdent
cut
'.style = activedocument.styles("normal")
end
activedocument.tables.add range:=selection.range, numrows:=1, numcolumns:= _
2, defaulttablebehavior:=wdword9tablebehavior, autofitbehavior:= _
wdautofitfixed

with selection.tables(1)
columns.preferredwidth = inchestopoints(3.5)
autoformat format:=wdtableformatgrid1, applyborders:=false, _
applyshading:=false, applyfont:=false, applycolor:=false, _
applyheadingrows:=false, applylastrow:=false, applyfirstcolumn:= _
false, applylastcolumn:=false, autofit:=false
end with


selection.tables(1)
borders(wdborderleft).linestyle = wdlinestylenone
borders(wdborderright).linestyle = wdlinestylenone
borders(wdbordertop).linestyle = wdlinestylenone
borders(wdborderbottom).linestyle = wdlinestylenone
borders(wdbordervertical).linestyle = wdlinestylenone
borders(wdborderdiagonaldown).linestyle = wdlinestylenone
borders(wdborderdiagonalup).linestyle = wdlinestylenone
borders.shadow = false
'set width of row, cell
cell(1, 1).setwidth _
columnwidth:=inchestopoints(3.5), _
rulerstyle:=wdadjustnone
cell(1, 2).setwidth _
columnwidth:=inchestopoints(3.5), _
rulerstyle:=wdadjustnone


end
selection.pasteandformat (wdformatoriginalformatting)
end sub


doug robbins - word mvp dkr[atsymbol]mvps[dot]org


Microsoft Office  >  Word IT Pro Discussions



Comments

Popular posts from this blog

CRL Revocation always failed

Failed to query the results of bpa xpath

0x300000d errors in Microsoft Remote Desktop client