+ Reply to Thread
Results 1 to 1 of 1

VBA Copy cell to word header/footer bookmark

  1. #1
    Registered User
    Join Date
    05-01-2017
    Location
    Budapest,Hungary
    MS-Off Ver
    12
    Posts
    1

    VBA Copy cell to word header/footer bookmark

    Hi,

    I have found a code that could help my work a lot (http://www.wiseowl.co.uk/blog/s199/word-bookmarks.htm) , it copies excel values to a bookmarked word template.
    This works well, however it cannot access the footers and the headers. I know lot of others had this problem before, but as I lack the knowledge (I have never used vba before) I only managed to put text in headers, but not cell values. So I would need what this code does, just I have some values that should go to the footer/header area. Is someone that could help me with this?


    Option Explicit
    'change this to where your files are stored
    Const FilePath As String = "C:\Users\Desktop\MT\"
    Dim wd As New Word.Application
    Dim PersonCell As Range
    Sub CreateWordDocuments()
    'create copy of Word in memory
    Dim doc As Word.Document
    wd.Visible = True
    Dim PersonRange As Range
    'create a reference to all the people
    Range("A1").Select
    Set PersonRange = Range( _
    ActiveCell, _
    ActiveCell.End(xlDown))
    'for each person in list �
    For Each PersonCell In PersonRange
    'open a document in Word
    Set doc = wd.Documents.Open(FilePath & "CL template.docx")
    'go to each bookmark and type in details
    CopyCell "MT1", 1
    CopyCell "MT2", 2
    CopyCell "MT3", 3
    CopyCell "MT4", 4
    'save and close this document
    doc.SaveAs2 FilePath & PersonCell.Value & " - MT letters" & ".docx"
    doc.Close
    Next PersonCell
    wd.Quit
    MsgBox "Created MTs in " & FilePath & "!"
    End Sub
    Sub CopyCell(BookMarkName As String, ColumnOffset As Integer)
    'copy each cell to relevant Word bookmark
    wd.Selection.GoTo What:=wdGoToBookmark, Name:=BookMarkName
    wd.Selection.TypeText PersonCell.Offset(0, ColumnOffset).Value
    End Sub
    Last edited by baljobb; 05-09-2017 at 09:24 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy excel sheet name to word footer or header
    By toronto1999 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-18-2016, 10:46 AM
  2. Header and Footer from Excel to Word
    By kittu55 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2016, 11:33 PM
  3. [SOLVED] How to add header/footer to new word document through excel
    By RonNCmale in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-30-2013, 03:07 AM
  4. Copy & Paste pictures from Excel into Header (and Footer) of Word
    By RogerPang in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2012, 04:52 AM
  5. vba code to search text in a word document header and footer
    By Excel-o-ratoR in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-12-2012, 03:16 AM
  6. Macro to change the dates in header & footer for all Word documents
    By olga6542 in forum Word Programming / VBA / Macros
    Replies: 2
    Last Post: 09-13-2010, 03:07 PM
  7. [SOLVED] How to copy cells excel data and paste them under MS Word bookmark
    By Bon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-17-2006, 11:40 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1