Log in

View Full Version : Losing Character formatting when pasting in table



mcramer
08-15-2010, 05:18 PM
Word 2010:

I have a macro that cuts some text and places it in a cell of a table. The first two words of the text always have bold character formatting.

When the macro pastes the text into the table, about half the time, the bold character formatting is lost. The other half of the time, the formatting is retained.

I'm pasting using Selection.PasteAndFormat (wdFormatOriginalFormatting)

Any clues as to why this might happen?

Sub PhotoTable()
With 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

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


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