PC Review


Reply
Thread Tools Rate Thread

Controling Word from Excel

 
 
Oggy
Guest
Posts: n/a
 
      30th Apr 2007
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

 
Reply With Quote
 
 
 
 
Ed
Guest
Posts: n/a
 
      1st May 2007
On Apr 30, 11:51 am, Oggy <ianchap...@ntlworld.com> wrote:
> 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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: controling excel from vba access and using sub procedures Stefan Hoffmann Microsoft Access VBA Modules 1 1st Feb 2010 05:15 PM
Controling Matlab from Excel =?Utf-8?B?U8O2cmVuX01hcm9kw7ZyZW4=?= Microsoft Excel Programming 1 1st Nov 2007 03:19 PM
Controling Styles in Word DennisC Microsoft Word Document Management 2 9th Feb 2007 09:22 PM
controling the spread of fields in the excel thread Microsoft Access Forms 5 9th Jan 2007 02:33 PM
Controling Excel using Word VBA =?Utf-8?B?Wm9sdGFyNTQ=?= Microsoft Excel Programming 8 21st Feb 2006 06:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:58 AM.