Consulting

Results 1 to 6 of 6

Thread: Solved: Automatic Pictures

  1. #1
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location

    Solved: Automatic Pictures

    I've attached a document with 4 tables cells. What we want to do is allow the user to run the macro and:

    1. Insert-Picture dialog comes up, and they choose a picture.
    2. The picture is immediately resized to 3.5 cm wide and 4.5 cm tall, and should probably be places as inline with text.
    3. The 3 tables cells to the right are immediately populated with the same picture.
    ~Anne Troy

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Anne,

    Not altogether sure where you are going with this but is something like this what you want ..
    [vba] Sub Piccy()
    If Selection.Information(wdWithInTable) Then
    ' So far, so good - for now assume 1 row 4 cells as sample
    Selection.Tables(1).Rows(1).Cells(1).Select
    Dialogs(wdDialogInsertPicture).Show
    With Selection.Cells(1).Range.InlineShapes(1)
    .LockAspectRatio = msoFalse
    .Width = CentimetersToPoints(3.5)
    .Height = CentimetersToPoints(4.5)
    .Range.Copy
    End With
    Selection.Tables(1).Rows(1).Range.Paste
    Else
    ' Error Message and Quit
    End If
    end sub
    [/vba]
    It'll need a bit of tidying up. Will your table always be one row of four empty columns? Should the insertion point be in it? should the cells be sized (or just the picture)? etc., etc. As I say, I'm not sure where you're going.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  3. #3
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    It's a beautiful thing, Tony.
    Works great!

    So...to use this, our user needs to:

    1. Copy the code above.
    2. Open their document that already has a one-row, 4-column table, formatted with centered paragraph formatting.
    3. Hit Alt+F11 to get to the Visual Basic Editor (VBE)
    4. Double-click ThisDocument on the left under their document's name.
    5. Paste the code in the right-hand window.
    6. Hit save to save the code permanently in this file.
    7. Close the VBE.
    To use the macro, they can either assign a toolbar button or shortcut key using Tools-Customize. They can save this file as a document template (DOT) and close it. Hit File-New and double-click it to get a new, blank document each time they want to do this with a new picture.



    FYI: I am asked questions elsewhere that I'm not always able to answer. When that happens, I'll ask here, and point the questioner here once resolved. That's the case with this one, and one of the reasons I left the HELP forums open to non-members. We don't want to force people to join.
    ~Anne Troy

  4. #4
    VBAX Regular
    Joined
    Jun 2004
    Posts
    8
    Location
    Thank you so much for this code!!

    I need it to allow me to get photos of taxi drivers and resize them for Id cards and record files.

    This will save so much time!

    Cheers


    John
    NYks UK

  5. #5
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    So you tried it and it works for you?
    ~Anne Troy

  6. #6
    VBAX Regular
    Joined
    Jun 2004
    Posts
    8
    Location
    Anne

    It works perfectly!

    Cheers


    John

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •