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 / July 2007

Tip: Looking for answers? Try searching our database.

Logo in Header - Macro Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan Kelly - 25 Jul 2007 11:54 GMT
All our documents have the company logo on them on Page 1 of the document.  
As this logo can be one of a number of colours I have the attached Macro that
makes the appropriate change.

In my latest document when the macro is first run, the new logo does not
change its position as per the end of the macro.  The second time the macro
is run the position changes, but not the colour.

Any suggestions?

Private Sub ChangeLogo()
   'Declare our variables
   Dim LogoName As String
   Dim x As Single, y As Single, h As Single, w As Single
   Dim oHeader As Word.HeaderFooter
   Dim rngA As Word.Range
   x = 0
   y = 0
   'Select Page 1 Header
   Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage)
   With oHeader
       'We Assume that there is only one shape in the header
       With .Shapes(1)
           x = .Left
           y = .Top
           h = .Height
           w = .Width
           Set rngA = .Anchor
       End With
       'Delete the Existing Image in the Header
       .Shapes(1).Delete
       ' Set the file to be inserted
       LogoName = SetLogoName
       .Shapes.AddPicture FileName:=LogoName, LinkToFile:=False,
SaveWithDocument:=True, _
           Left:=x, Top:=y, Width:=w, Height:=h, Anchor:=rngA
       'Reposition the logo?
       .Shapes(1).RelativeHorizontalPosition =
wdRelativeHorizontalPositionPage
       .Shapes(1).RelativeVerticalPosition = wdRelativeVerticalPositionPage
       .Shapes(1).Left = x
       .Shapes(1).Top = y
   End With
End Sub
Dan Kelly - 25 Jul 2007 12:56 GMT
OK partially solved.

The document in question has 3 Shapes that can be identified.  I had assumed
that as the others were in Section(2) I would be safe, but obviously not.

I assume that the newly pasted shape is being pasted as shape 4 (or maybe 3).

Any more tips?

> All our documents have the company logo on them on Page 1 of the document.  
> As this logo can be one of a number of colours I have the attached Macro that
[quoted text clipped - 40 lines]
>     End With
> End Sub
Russ - 30 Jul 2007 04:38 GMT
Dan,
Assign a meaningful name to your shape.
From Word VBA help for shapes/'Shapes Collection Object'
>>>>Quote
Each shape is assigned a default name when it is created. For example, if
you add three different shapes to a document, they might be named "Rectangle
2," "TextBox 3," and "Oval 4." To give a shape a more meaningful name, set
the Name property.
>>>>UnQuote

> OK partially solved.
>
[quoted text clipped - 49 lines]
>>     End With
>> End Sub

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
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.