View Full Version : Heading Format from excel to word

12-18-2009, 09:30 AM
I'm using excel for calculations then coping and pasting pictures of the calculations into word... I need a heading before each set of calculations that is also copied from excel.. this code works great EXCEPT I can't get the code to format the heading into a "Word Heading".. I need that for my table of contents... here's my part of my code... the last line is the line with the error... any help would be great.

Sub Macro2()
' Macro2 Macro
' Keyboard Shortcut: Ctrl+e
'Copy selection

'Grey Out
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With

'Cell 1 of lookup "yellow" row
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

'Select Header cell from macro 1
'Clear the clipboard
Application.CutCopyMode = False
'Copy the header

'Define and assign word document
Dim AppWord As Word.Application
Dim wDoc As Word.Document

'Create a Word application, make the Word instance visible and add a new document
'Go to tools / references and turn on Microsoft Word 12 Object Library
Set wApp = CreateObject("Word.Application.12")
wApp.Visible = True
Set wDoc = wApp.Documents.Open(Filename:="N:\Steel - Connections\CopyDoc.docx")

'Paste the header into word doc
wApp.Selection.PasteSpecial DataType:=wdPasteText
wApp. Selection.Style = ActiveDocument.Styles("Heading 1")

Edited 23-Dec-09 by geekgirlau. Reason: insert vba tags

12-18-2009, 10:34 AM
Seems to be OK.. what is the error message?

12-22-2009, 09:47 PM
There's a space in the last line before Selection ...