PDA

View Full Version : Word Automation



smnathan
11-09-2004, 02:54 AM
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.

Jacob Hilderbrand
11-09-2004, 03:08 AM
Try this.
Selection.GoTo What:=wdGoToHeading, Which:=wdGoToFirst
Selection.SplitTable

mdmackillop
11-09-2004, 03:27 PM
Hi Nathan,

Expanding on DRJ's solution with recorded steps

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