+ Reply to Thread
Results 1 to 2 of 2

Automation: Create Word file from Excel

  1. #1
    Steve C.
    Guest

    Automation: Create Word file from Excel

    Hi there,
    I need to create a Word document from Excel in which I would like to insert
    the date/time and file name (insert Auto Text) in the header through VBA. In
    fact, I can create the Word file from Excel but encounter error when it comes
    to inserting date and file name in the header.
    Appreciate if anyone is kind enough to help me out.

    Thanks in advance for your kind assistance!
    Regards,

    Steve C.

  2. #2
    Forum Contributor
    Join Date
    12-11-2004
    MS-Off Ver
    2007
    Posts
    137
    Hello Steve

    I'm not sure that is exactly what you need , but this macro create and save a Word doc , then insert the date and the name in the header



    Sub insertInformation_Header()
    'Activate Microsoft Word xx.x Object Library
    Dim WordApp As Word.Application
    Dim WordDoc As Word.Document

    Set WordApp = CreateObject("Word.Application")
    WordApp.Visible = True
    Set WordDoc = WordApp.Documents.Add

    WordDoc.SaveAs Filename:="C:\myDoc.doc"
    With WordDoc.Sections(1)
    .Headers(wdHeaderFooterPrimary).Range.Text = Date & " " & Time _
    & vbLf & WordDoc.Name
    .Headers(wdHeaderFooterPrimary).Range.Paragraphs.Alignment = wdAlignParagraphLeft
    End With

    End Sub



    regards ,
    michel

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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