Controling Word from Excel

O

Oggy

Hi

I have a macro where the infomation is being coppied from excel and
putting it in a word document. I can setup the font type and size
etc... no problems. What i would like to do is setup a header and a
footer in my excel macro and if i can set the pageup as well. Can
anyone point me in the right direction?

Thanks

Oggy


' Send commands to Word
With WordApp
.Documents.Add



With .Selection
.Font.name = "Times New Roman"
.Font.Size = 10
.Font.Bold = False
.Font.Italic = False
.ParagraphFormat.Alignment = 1
.TypeText Text:="QUOTATION"
.TypeParagraph
 
C

Cindy M.

Hi Oggy,
I have a macro where the infomation is being coppied from excel and
putting it in a word document. I can setup the font type and size
etc... no problems. What i would like to do is setup a header and a
footer in my excel macro and if i can set the pageup as well. Can
anyone point me in the right direction?
Well, the first thing you have to learn when working with Word is to
NOT use the Selection object. As with Excel programming, you need to
learn to work with Ranges in Word. In Word, a Range is any string of
contiguous characters on the "page"; it can contain anything from a
single character to the entire "story" in question.

So your existing macro should look more like this

' Send commands to Word
Dim doc as Word.Document
Dim rngDoc as Word.Range
Dim rngHeader as Word.Range
With WordApp
Set doc = .Documents.Add
Set rngDoc = doc.Content
Set rngHeader =
rngDoc.Sections(1).Headers(wdHeaderFooterPrimary)

With rngDoc
.Font.name = "Times New Roman"
.Font.Size = 10
.Font.Bold = False
.Font.Italic = False
.ParagraphFormat.Alignment = 1
.Text Text:="QUOTATION" & vbCr
End With

With rngHeader
.Text = "Left side" & vbTAB & "Center" & vbTAB & "right side"
End With

doc.Sections(1).PageSetup.LeftMargin =
WordApp.InchesToPoints(1.5)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top