Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2004

Tip: Looking for answers? Try searching our database.

Programatically inserting a logo in the header

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robin - 30 Mar 2004 16:51 GMT
Hi

does anyone know how to insert on demand an eps logo in the header of a document programatically.  I need to be able to insert (or not insert) a file in the header based on a flag setting in a useform but I cannot seem to get the thing to work.  Help would be greatly appreciated

Thank you
Jay Freedman - 30 Mar 2004 18:45 GMT
> does anyone know how to insert on demand an eps logo in the header of
> a document programatically.  I need to be able to insert (or not
> insert) a file in the header based on a flag setting in a useform but
> I cannot seem to get the thing to work.  Help would be greatly
> appreciated

Hi Robin

Here are two suggestions:

1. If the logo must remain in a separate file (for instance, if it's updated
frequently), you can use code like this:

Sub AddLogoFromFile()
  Dim MyRange As Range
  Dim MyInlineShape As InlineShape

  Set MyRange = Selection.Sections(1) _
     .Headers(wdHeaderFooterPrimary).Range
  MyRange.Collapse wdCollapseEnd

  Set MyInlineShape = MyRange.InlineShapes.AddPicture _
     (FileName:="C:\Graphics\NightWatch.jpg", _
     linktofile:=False, savewithdocument:=True, _
     Range:=MyRange)

  With MyInlineShape
     .Height = 0.5 * .Height
     .Width = 0.5 * .Width
  End With
End Sub

Of course, the FileName should point to your file. As long as it's a file
type that Word has a converter for, this will work. You can insert it as an
InlineShape, or you can change the macro to insert it as a floating Shape --
then you'll want to add statements to the With group to set its .Top and
.Left as well.

Also, you may need to change where MyRange is -- possibly in the first-page
header (change the constant to wdHeaderFooterFirstPage) or in some specific
section independent of the Selection.

2. Less convenient for updating but easier to distribute to others, you can
make an AutoText entry containing the pre-sized logo and store it in the
template on which the document will be based. Then the code looks like this:

Sub AddLogoFromAutoText()
  Dim MyRange As Range
  Dim ATtemplate As Template

  Set MyRange = Selection.Sections(1) _
     .Headers(wdHeaderFooterPrimary).Range
  MyRange.Collapse wdCollapseEnd

  Set ATtemplate = ActiveDocument.AttachedTemplate
  ATtemplate.AutoTextEntries("NightWatch").Insert _
     where:=MyRange, RichText:=True
End Sub

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

Leila - 01 Apr 2004 00:36 GMT
Hi Peter, Jay
I'm doing almost the same thing to insert a logo to the
footer section but have problem with removing it could you
please provide a solution for the remove method too.
Thanks,
Leila  
>-----Original Message-----
>Hi
>
>does anyone know how to insert on demand an eps logo in the header of a document programatically.  I need to be
able to insert (or not insert) a file in the header based
on a flag setting in a useform but I cannot seem to get
the thing to work.  Help would be greatly appreciated

>Thank you
>.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.