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
 
E

Ed

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

Hi, Oggy. I'm assuming that you have an object set to WordApp, and a
reference set to Word (Tools >> References). Set an object to your
document -
Dim WordDoc As Word.Document
Set WordDoc = WordApp.Documents.Add
Then do not use the Selection object - use your document object.

With the document object, PageSetup will get you into all your
margins, and Content will get you the range to set font stuff for the
whole document. To type specfic text at specific paragraphs, use
something like
WordDoc.Paragraphs(1).Range.Text = "QUOTATION" & vbCrLf
You can use the Range object of specific paragraphs to set font
attrubutes for just those paragraphs.

The header and footer are a but more complicated. Each section has a
header and a footer (and it gets deeper than that, but you don't want
to go there if you don't have to!). So you have to first get into the
appropriate document section, then either the Header or Footer object
for that section. SInce you are creating a brand new document, unless
you are using a custom template, it should come fresh out of the box
with only one section. That makes things easy enough to set an object
to what you need.
Dim HdFt As HeaderFooter
Set HdFt = WordDoc.Sections(1).Headers(wdHeaderFooterFirstPage)
' Do what you need here
Set HdFt = WordDoc.Sections(1).Footers(wdHeaderFooterFirstPage)
' Do what you need here

Hope this helps some. You might want to post over to
microsoft.Word.VBA.general for more assistance.

Ed
 

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