Consulting

Results 1 to 3 of 3

Thread: Heading Format from excel to word

  1. #1
    VBAX Newbie
    Joined
    Dec 2009
    Posts
    1
    Location

    Heading Format from excel to word

    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.

    [vba]
    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")
    [/vba]

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

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    Seems to be OK.. what is the error message?
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    There's a space in the last line before Selection ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •