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 / September 2005

Tip: Looking for answers? Try searching our database.

Insert picture into a table in header

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sol Apache - 04 Sep 2005 12:49 GMT
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.
Sol Apache - 04 Sep 2005 15:33 GMT
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

On 4/9/05 12:49, in article BF409DF0.764A%Sol@solapache.com, "Sol Apache"
<Sol@solapache.com> wrote:

> 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
[quoted text clipped - 53 lines]
>
> Thanks for any help and thanks very much Jay for this excellent macro.
Doug Robbins - 04 Sep 2005 16:01 GMT
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.

Signature

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

> Oops, have just reread the last bit of the macro and it does say inline.
> Would appreciate advice about the other two queries, though
[quoted text clipped - 73 lines]
>>
>> Thanks for any help and thanks very much Jay for this excellent macro.
Sol Apache - 04 Sep 2005 19:13 GMT
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.

On 4/9/05 16:01, in article uchQOGWsFHA.3216@TK2MSFTNGP12.phx.gbl, "Doug
Robbins" <dkr@REMOVEmvps.org> wrote:

> The following code will allow the user to select the folder that contains
> the pictures
[quoted text clipped - 18 lines]
>
> To delete anything from the cell, delete the .Range of the cell.
Doug Robbins - 04 Sep 2005 20:59 GMT
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.

Signature

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

> Thanks Doug. This presumably opens a dialog box, but I wanted to ³hard
> wire²
[quoted text clipped - 28 lines]
>>
>> To delete anything from the cell, delete the .Range of the cell.

Rate this thread:






 
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.