Insert picture into a table in header

S

Sol Apache

In September last year Jay Freeman provided this macro for Sean which is
just about perfect for my needs for putting a picture into a cell in a
header (actually six different pictures into 6 cells):

Dim oRng As Range

On Error Resume Next
ActiveDocument.CustomDocumentProperties.Add _
Name:="ClientLogPath", _
LinkToContent:=False, Value:="", _
Type:=msoPropertyTypeString
On Error GoTo 0

With Dialogs(wdDialogInsertPicture)
If .Display Then
'Populate the DocProperty with file path
ActiveDocument.CustomDocumentProperties( _
"ClientLogPath").Value = _
WordBasic.FilenameInfo$(.Name, 1)

Set oRng = ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary).Range _
.Tables(1).Cell(1, 2).Range

' The next line has nothing to do with the Range!
'Selection.Collapse Direction:=wdCollapseStart

ActiveDocument.InlineShapes.AddPicture Range:=oRng, _
FileName:=ActiveDocument.CustomDocumentProperties( _
"ClientLogPath").Value
End If
End With


I have two solvable problems with this.

1. I would like to specify an actual folder name rather than ³ClientLogPath²
which opens to the last directory I have opened (or to the default one if
this macro is run for the first time). I have tried putting in the pathname
but the macro ignores this and opens to my last folder. Where do I put the
specific pathname? Or how do I change the macro to achieve this?

2. I would like to replace any picture which may already be in the cell
rather than adding the picture to the left of it. How do I select a picture,
if there is one, and have it replaced?

The unsolvable problem is that I had set the table to allow spacing between
cells. When putting in the picture Word fits the picture proportionately
inline with text but it overlaps the bottom margin. This is perhaps a Word
bug and I have redrawn my table with tiny margin cells between each picture
cell.

Finally, at the moment on my Mac the macro puts the picture proportionately
inline with text, but will this automatically work on the PCs on which the
template will be used or does there need to be a specific mention of inline
with text within the macro?

Thanks for any help and thanks very much Jay for this excellent macro.
 
S

Sol Apache

Oops, have just reread the last bit of the macro and it does say inline.
Would appreciate advice about the other two queries, though

Many thanks

Sol
 
D

Doug Robbins

The following code will allow the user to select the folder that contains
the pictures

Dim MyPath As String

'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() <> -1 Then Exit Sub
MyPath = .Directory
End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If

'MyPath will now contain the path to the folder that the user selected

To delete anything from the cell, delete the .Range of the cell.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Sol Apache

Thanks Doug. This presumably opens a dialog box, but I wanted to ³hard wire²
a file path (directory path) within the macro.

Also I have tried your ³delete the .range² but the macro keeps stopping
here. Obviously I do not know the proper syntax to get it to work.
 
D

Doug Robbins

If you include the following in your code

Options.DefaultFilePath(wdPicturesPath) = "C:\Documents"

when the Insert>Picture>From File menu item is used, the C:\Documents folder
will be opened in the File>Insert Picture dialog.

Change the C:\Documents to the path that you desire.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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