pukiee
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
Selection.Copy
'Grey Out
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
'Cell 1 of lookup "yellow" row
Range("K106").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'Select Header cell from macro 1
Range("C106").Select
'Clear the clipboard
Application.CutCopyMode = False
'Copy the header
Selection.Copy
'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
Sub Macro2()
' Macro2 Macro
' Keyboard Shortcut: Ctrl+e
'Copy selection
Selection.Copy
'Grey Out
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
'Cell 1 of lookup "yellow" row
Range("K106").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'Select Header cell from macro 1
Range("C106").Select
'Clear the clipboard
Application.CutCopyMode = False
'Copy the header
Selection.Copy
'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