PDA

View Full Version : Word 'Drawing Tools' in a Header



GRCNC
11-30-2016, 06:36 AM
Hi - I've got a macro that opens up several word documents and copies them into 1 document. Each page of the documents has a 'Header' & 'Footer' and within these, there are graphics (IE: lines created from the 'Drawing' menu). Most of these lines with the Header and Footer are coming over correctly (IE: same Position / layout / length, etc), but every so often, on a few of the pages, these lines are slightly skewed (IE: incorrect position).

Not sure why this is happening, but I was going to try to correct it by recording a macro and having all of these section auto-correct after all of the documents had been copied over. However, I'm unable to access the 'Header & Footers' menu when I record a macro.

Does anyone know how to overcome this? I presume that I could write code, but I can't find a sample on the Internet. I'm trying to access the "Layout" / "Position" menu and use "Absolute position".

any help would be greatly appreciated.

Thanks,

GRC

gmayor
11-30-2016, 11:06 PM
Frankly the last thing you need to do is access the menu. You need to identify the shape to the macro and apply the appropriate values to the shape. Things like this cannot be done with the macro recorder, and without a sample of the document that shows the problem, it is difficult to suggest appropriate code to address it.

Basically you need to loop through the sections in the document, then in each section loop through the header and footer ranges and then identify to the macro the shape(s) that need to be addressed. e.g.


Sub Macro1()
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
Dim oShape As Shape
For Each oSection In ActiveDocument.Sections
For Each oHeader In oSection.Headers
If oHeader.Exists Then
For Each oShape In oHeader.Shapes
'do something with oshape
Next oShape
End If
Next oHeader
For Each oFooter In oSection.Footers
If oFooter.Exists Then
For Each oShape In oFooter.Shapes
'do something with oshape
Next oShape
End If
Next oFooter
Next oSection
End Sub