+ Reply to Thread
Results 1 to 6 of 6

VBA to change current picture and keep position and size

  1. #1
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    695

    VBA to change current picture and keep position and size

    Hi

    I have word file with sample image
    with userform1, I want to pick new image from PC, and replace it with current image, without change the current position and size

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Guru macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,646

    Re: VBA to change current picture and keep position and size

    The simplest way is to create a single-cell table with a fixed height and width wherever you want the image to go, then insert the image into that. The inserted image will resize, at the correct aspect ratio for the picture, to fit the space available. Replacing the image then becomes a simple matter of deleting the old one and inserting the new one into the same table. That way there's no need to mess around with VBA trying to work out horizontal/vertical positioning or height and width.

    To create a single-cell table with a fixed height and width, use Insert|Table and choose one cell. Then, for the:
    rows, set the exact row height under Table Tools>Layout>Properties>Row>Specify Height>Exactly.
    columns, set the preferred column width under Table Tools>Layout>Properties>Columns,
    and uncheck the 'automatically resize to fit contents' option under Table Tools>Layout>Properties>Table>Options. You might also want to set the cell margins to 0 all round. It's also a good idea to format the table paragraph with 0 before/after spacing.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    695

    Re: VBA to change current picture and keep position and size

    Thanks you for good idea, I try same idea with shape and its working using fill with picture, its better than table, but I still need VBA to pick the new pic and put it in fill shape picture using the userform

    this is a part from my userform

  4. #4
    Forum Guru macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,646

    Re: VBA to change current picture and keep position and size

    Here's some code for selecting inserting an image into a table. I don't know what your shape parameters are.
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    695

    Re: VBA to change current picture and keep position and size

    Thank you! working with table
    I add your code, just change the range from table to shape "Rectangle 2"
    and use change pic for the shape
    Thanks!
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    695

    Re: VBA to change current picture and keep position and size

    Thank I got it

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Modify code to replace picture with new size and position.
    By noelmus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-16-2020, 07:06 PM
  2. Macro to change picture size according to cell value
    By jono7gold in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-11-2014, 10:25 AM
  3. [SOLVED] Change Shape Size / Keep its Position
    By Broobi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2014, 12:05 PM
  4. How to change or standardize size and position of plot areas
    By tensor9 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 06-17-2013, 06:59 AM
  5. Change size and position of Buttons on Excel sheet?
    By excelbobabc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-16-2009, 11:01 PM
  6. [SOLVED] How do I change default picture size
    By submerj in forum Excel General
    Replies: 1
    Last Post: 08-02-2005, 02:05 PM
  7. [SOLVED] ho to change in the bubble chart the bubble position and size
    By laszlo in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 03-25-2005, 01:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1