Re: Image Replacement Macro Crash



Hi Dan

Oh dear. I'm sure InDesign is fabulous software, and I have great respect
for the brilliant ideas of graphic designers, but I was really hoping that
2007 would be a year in which I could stop hearing about the problems of
beautiful, but completely impractical, designs.

I suggest the following steps:

1. Trick up something that's moderately close to the proposed design using
only inline shapes.

2. Take it to the PR department and ask them to sign off on the budget to
muck around with positioning floating shapes to better (not necessarily
accurately!) reflect the proposed design.

3. Explain to PR that what's possible on a Mac in InDesign is not
necessarily possible in Windows in Word.

4. If that doesn't work, you'll need to expand your code so that you
explicitly set every setting of each shape.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


"Dan Kelly" <DanKelly@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:DAADB2F8-3A18-429A-91D5-2B10680A1EAA@xxxxxxxxxxxxxxxx
Basically the reasons are being able to get the implementation of the
design
passed on from our PR dept.

We have a repeating 1 inch header on each page - which is blank on page
1 -
with the logo starting a couple of inches down from bottom of the header.

The Address Block runs in a text box parallel to the logo, overrunning the
header area if needed (it fills from the bottom up).

PR use InDesign and ask us to replicate their design decisions in Word.
We
do our best, but the guy who used to do the Word Design left about a year
ago
- I think he saw this redesign coming ;-)

"Shauna Kelly" wrote:

Hi Dan

Is there a good reason that you're using a floating Shape and not an
InLineShape? All of these problems would go away if you could position
the
logo inline.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


"Dan Kelly" <DanKelly@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A1146F1B-BB97-4C0B-8F3D-8BAC54A9E6A1@xxxxxxxxxxxxxxxx
Thanks for the help Shauna - after a bit more testing I've got an extra
problem associated with this:

The first image replace sticks the Logo further Down and Right than
expected
so I adapted the x and y values as below:

x = .Top - ActiveDocument.PageSetup.HeaderDistance
y = .Left - ActiveDocument.PageSetup.LeftMargin

Whic puts the image in the correct place.

However it seems that the New logo has pastes in with different
alignment
properties than the original - namely Col & Para Alignment rather than
Page.

If I want to preserve Page alignment for distances, rather than Column
and
paragraph, do I have any option other than the following:

'Insert the logo
.Shapes.AddPicture FileName:=LogoName, LinkToFile:=False, _
SaveWithDocument:=True, Left:=y, Top:=x, Width:=w, _
Height:=h, Anchor:=rngA
'Reposition the logo
.Shapes(1).RelativeHorizontalPosition =
wdRelativeHorizontalPositionPage
.Shapes(1).RelativeVerticalPosition =
wdRelativeVerticalPositionPage
.Shapes(1).Top = x
.Shapes(1).Left = y

"Shauna Kelly" wrote:

Hi Dan

If you look at VBA's help for .Shapes.AddPicture, you'll see that the
..Anchor needs to be a range.

This code:
Dim LogoName, x, y, h, w, a
has created variables all of which are Variants.

This code
a = Selection.HeaderFooter.Shapes(1).Anchor
won't work because the .Anchor property is returning a Range, which is
an
object, and so you need to use Set.

So better would be:
Dim rngAnchor as word.range

Set rngAnchor = Selection.HeaderFooter.Shapes(1).Anchor


More generally, using the Selection is generally to be avoided. In
your
case, this code
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
is a bit of a hit or miss affair, because you don't really know what
header
you're selecting.

Assuming that your logo is in the First Page header (and that the
document
is displaying first page headers), then this is a safer way:

Private Sub ChangeLogo2()

Dim LogoName As String
Dim x As Single, y As Single, h As Single, w As Single
Dim oHeader As Word.HeaderFooter
Dim rngAnchor As Word.Range

Set oHeader =
ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage)

With oHeader
' Store the existing Image details
With .Shapes(1)
x = .Top
y = .Left
h = .Height
w = .Width
Set rngAnchor = .Anchor
End With

'Delete the first shape in the header
.Shapes(1).Delete

'Set LogoName to Desired Color (function)
LogoName = SetLogoName

' Add the desired image to the form
.Shapes.AddPicture FileName:=LogoName, LinkToFile:=False, _
SaveWithDocument:=True, _
Left:=y, Top:=x, Width:=w, Height:=h, _
Anchor:=rngAnchor
End With

End Sub

For what it's worth, I'd add some error checking to make sure that
there
is
an existing shape.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word


"Dan Kelly" <DanKelly@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1009974C-8A67-44DA-A7FB-C96B4855C24B@xxxxxxxxxxxxxxxx
I am trying to replace a log in the header of a letter with a similar
logo
of
a different color.

The user picks the colour using the SetLogoName function, but all
the
other
details should be identical between the existing logo and the new
one.

At the moment My code looks like this:

Private Sub ChangeLogo()
Dim LogoName, x, y, h, w, a

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
' Store the existing Image details
Selection.HeaderFooter.Shapes(1).Select
x = Selection.HeaderFooter.Shapes(1).Top
y = Selection.HeaderFooter.Shapes(1).Left
h = Selection.HeaderFooter.Shapes(1).Height
w = Selection.HeaderFooter.Shapes(1).Width
a = Selection.HeaderFooter.Shapes(1).Anchor
'Delete the exisitng image
Selection.ShapeRange.Delete
'Set LogoName to Desired Color (function)
LogoName = SetLogoName
' Add the desired image to the form
ActiveDocument.Shapes.AddPicture FileName:=LogoName,
LinkToFile:=False,
SaveWithDocument:=True, _
Left:=y, Top:=x, Width:=w, Height:=h, Anchor:=a
End Sub

Ommiting the Anchor from the AddPicture statement places the image
in
the
body of the document rather than the header. Inheriting the Anchor
from
the
existing image (as above) causes a crash, whilst using the following
Anchor:

Anchor:=ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range

Messes up the top/left positioning.

Any suggestions?








.



Relevant Pages

  • Re: Image Replacement Macro Crash
    ... with the logo starting a couple of inches down from bottom of the header. ... The Address Block runs in a text box parallel to the logo, ... Dim rngAnchor as word.range ... Dim LogoName As String ...
    (microsoft.public.word.vba.general)
  • Re: page header not visible
    ... why would a form's page header section not appear in regular view? ... in design view it is there - sized to about 1.2" with a logo and one ... The Form's Page Header is ONLY visible when the form is printed. ...
    (microsoft.public.access.forms)
  • Re: How can I insert BOTH a header and upper-right page numbering
    ... MS is, in the end a profit oriented business, and their goal, like many businesses is to enlarge the customer base and increase ... I doubt that Microsoft made the product design decisions on the basis that they thought people were dumb, ... The building blocks, of which the Quick Parts gallery is only one of 36 ... What a building block for a header does, in this case, is give you the ability to not be concerned with creating and rechecking the ...
    (microsoft.public.word.docmanagement)
  • Re: changing control props in datasheet view for active record
    ... >> index named PrimaryKey, ... >> conditional formatting will only be applied to one record. ... >>>> Look at the subform's Form object in design view. ... >>>> the Form Header section exists. ...
    (microsoft.public.access.formscoding)
  • Re: FreeBSDs Visual Identity: Outdated?
    ... No you don't - would you prefer multi-colored windows? ... > Redo the whole logo in photoshop with a bold, ... > are unprofessional (the logos at the bottom of the page: FreeBSD MALL, ... Do I really care if a design has ...
    (freebsd-arch)