Consulting

Results 1 to 3 of 3

Thread: Word Automation

  1. #1
    VBAX Newbie
    Joined
    Sep 2004
    Posts
    5
    Location

    Word Automation

    Hi

    This is Nathan.S. I had one problem while automating word document. I have a word document with one table (actually this a document generated by output to rtf from MS Access database). I have to insert one line (report heading) in the top of the document. Problem is when I try to insert a line its getting inserted in the first cell of the table. So please help me in solving this problem. I have attached the following two documents with this.Thanks in advance.



    • Doc1.rtf


    This is the original document generated from MS Access. We have to add one or two lines in the top of the document.



    • Doc2.rtf


    This is the final document after adding the heading.

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try this.
    [VBA] Selection.GoTo What:=wdGoToHeading, Which:=wdGoToFirst
    Selection.SplitTable
    [/VBA]

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Nathan,

    Expanding on DRJ's solution with recorded steps

    [VBA] Option Explicit

    Sub MacroAddHeading()
    Selection.GoTo What:=wdGoToHeading, Which:=wdGoToFirst
    Selection.SplitTable
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.HomeKey Unit:=wdStory
    Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
    Selection.Font.Bold = True
    Selection.Font.Size = 16
    Selection.TypeText Text:=InputBox("Document Heading")
    Selection.MoveDown Unit:=wdLine, Count:=2
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.Font.Bold = True
    Selection.Font.Size = 12
    Selection.TypeText Text:="Date: "
    Selection.InsertDateTime DateTimeFormat:="dd/MM/yy", InsertAsField:=False, _
    DateLanguage:=wdEnglishUK, CalendarType:=wdCalendarWestern, _
    InsertAsFullWidth:=False
    Selection.HomeKey Unit:=wdStory
    End Sub


    [/VBA]

Posting Permissions

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