PDA

View Full Version : Unwanted change of font while pasting into Word



Rejje
12-10-2010, 01:39 AM
Hi!

When using this I get a strange problem (code is located in Excel). In case font to paste is Times New Roman in Excel it will change to Calibri in Word. If font was Arial in Excel it pastes as Arial in Word. What's the problem?

wrdApp.Selection.PasteExcelTable False, False, False

macropod
12-10-2010, 03:28 AM
Hi Rejjie,

What Styles are assigned to the Excel cells and how are the corresponding Styles defined in Word?

Rejje
12-10-2010, 04:17 AM
Hmm... I'm not quite sure what you mean (I am a newbie when it comes to such things as these).

I'll explain a little furtermore:


1. I want to copy a certain area, "TXT_101", which is defined in a cell called "V_20500". Reason for having the address to copy in a single cell is that it could just as well say something else, like "TXT_412". I'll call it "TXT_X" as it's a variant.

"TXT_X" is always located in another worksheet than cell "V_20500". .
"TXT_X" might be a single cell but may also be an area concisting of many columns and rows.
"TXT_X" can contain 1 to 3 different fonts like Times New Roman, Arial, Berling Original etc.

2. Then I want the macro to paste "TXT_X" into a specific Word template. This template is always set on Times New Roman size 10 because of many different reasons such as policies etc.

I want the macro to paste into Word exactly as the copied area i Excel!

Below macro doesn't do the trick...

Sub CreateWordDoc8()
Dim wrdApp As Object
Dim wrdDoc As Object
Dim xlDoc As Workbook
MkDir Range("V_20200").Value
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open(Range("V_20400").Value)
Set xlDoc = ActiveWorkbook

With xlDoc

Application.Goto Reference:=Range("V_20500").Value
Selection.Copy

End With

wrdApp.Selection.PasteExcelTable False, False, False

If Dir(Range("V_21700").Value) <> "" Then
Kill Range("V_21700").Value
End If
wrdDoc.SaveAs Range("V_21700").Value
wrdDoc.Close
wrdApp.Quit
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub

macropod
12-10-2010, 10:35 PM
Hi Rejjie,

In Excel, a formatting style (& style name) gets applied to each cell. My understanding is that if you copy a cell with a Style named 'Normal' and paste that into a Word document, it will pick up the Word document's 'Normal' style definition. You can tell Word, however, to apply the formatting from the origin when pasting content - See under Word Options|Advanced > Cut copy & paste.