Shapes and headers

K

kaldvelski

Hi folks,

I'm using the ViewHeader routine to check that a user doesn't mess with
my headers and footers. If they don't match what I want them to be I'm
changing the content back. Part of my header is an image (shape) that
basically serves as a watermark.

The problem is that by adding a shape into the header triggers the
ViewHeader routine so my code ends up in an infinite loop which can
crash word. So not good.

Adding the image as an inline shapes seem to get past the infinite loop
problem but then I can't convert use the ConvertToShape function
without
either triggering ViewHeader again or it just failing (I believe
because
I've closed the HeaderFooter edit pane).

I've even tried inserting the image into the main body of the document,
then cut and pasting it into the header but that still fires the
ViewHeader method.

Any other suggestions how I might go about doing this?

TIA

Craig
 
S

Steve Rindsberg

Hi folks,

I'm using the ViewHeader routine to check that a user doesn't mess with
my headers and footers. If they don't match what I want them to be I'm
changing the content back. Part of my header is an image (shape) that
basically serves as a watermark.

The problem is that by adding a shape into the header triggers the
ViewHeader routine so my code ends up in an infinite loop which can
crash word. So not good.

It's always better to post the relevant bits of code. But one approach to
solving the problem is to use a Publically declared boolean "flag" variable.

Your routines can set this true when you're adding a shape; the view header
routine can check the variable and perform any further actions if it's false
(then either way, set it to false on exit)
 
K

kaldvelski

I've tried using a flag but the problem is it never gets reset because
ViewHeader seems to override the current VBA execution thread and stops
processing my main routine. It stops the loop once but then my code
never gets executed again.

Here's the salient piece of code

'Check for the watermark
1167 If .IsHeader And .Shapes.Count < 2 Then
'Check if we have the image file in the locals temp
directory
Dim WATERMARK As String
1168 WATERMARK = Environ$("TEMP") & "\logowatermark.jpg"
Dim fso As New FileSystemObject
1169 If Not fso.FileExists(WATERMARK) Then
'Download the file
Dim server As New ServerComms
1170 server.downloadWatermark WATERMARK
1171 End If
Dim watermarkImg As InlineShape, watermarkShp As
Shape
1172 If fso.FileExists(WATERMARK) Then
1173 Set fieldRng = rangeToCheck.range
1174 fieldRng.Collapse wdCollapseEnd
1175 Set watermarkImg =
..range.InlineShapes.AddPicture(FileName:=WATERMARK, linkToFile:=False)
1176 Set watermarkShp = watermarkImg.ConvertToShape
1177 If Not watermarkShp Is Nothing Then
1178 watermarkShp.top = 300
1179 watermarkShp.left =
rangeToCheck.Parent.PageSetup.LeftMargin
1180 End If
1181 End If
1182 End If

The problem is line 1175 which then re-initiates the whole process so
my image is stuck in the header and never gets converted to the shape.

Thanks

Craig
 
S

Steve Rindsberg

I've tried using a flag but the problem is it never gets reset because
ViewHeader seems to override the current VBA execution thread and stops
processing my main routine. It stops the loop once but then my code
never gets executed again.

I may be going blind. I don't see ViewHeader called here (but I note in the
help file that there are VBA equivalents for it (it seems to be a Word Basic
command)? Perhaps it'd be a good idea to start by using the VBA version
instead?
 

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