+ Reply to Thread
Results 1 to 6 of 6

Two macros to insert and resize pictures interfering with each other

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-27-2022
    Location
    MS, USA
    MS-Off Ver
    Microsoft 365
    Posts
    146

    Two macros to insert and resize pictures interfering with each other

    Hi,

    I have two macros that insert pictures and resize them into certain cells.
    - One is a Good Picture cell[K37] and the other a No Good [E38] Picture cell.
    - If you click on them, it will open a browser window to select a picture.
    - If I enter just a Good or a No Good Picture, I have no problems. But if I enter both in, it will resize and position the both pictures.

    2nd request
    - I was hoping to have the pictures entered into K37 be copied and resized to the 2nd worksheet, cell [c13:e18] and the same for E38 to cell [h13:j18]

    Thank you.
    Attached Files Attached Files
    Last edited by Ajaxs87; 03-10-2023 at 02:02 PM.

  2. #2
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Two macros to insert and resize pictures interfering with each other

    try this line of code
    ActiveSheet.Pictures(Nn).Delete
    and this
    ActiveSheet.Pictures(N).Delete
    Last edited by AC PORTA VIA; 03-09-2023 at 06:00 PM.

  3. #3
    Forum Contributor
    Join Date
    03-27-2022
    Location
    MS, USA
    MS-Off Ver
    Microsoft 365
    Posts
    146

    Re: Two macros to insert and resize pictures interfering with each other

    Quote Originally Posted by AC PORTA VIA View Post
    try this line of code
    ActiveSheet.Pictures(Nn).Delete
    and this
    ActiveSheet.Pictures(N).Delete
    You are awesome!

    That helps with the 1st part of my question. If you have any advice for the last line in my last post, I would really appreciate your advice. Thank you!

  4. #4
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Two macros to insert and resize pictures interfering with each other

    try below
    Sub ImportGoodPicture()
        Dim WkShape As Shape
        
        ' Step 1: Open a directory to select a picture on the PC to open
        Dim picFile As Variant
        picFile = Application.GetOpenFilename("Pictures (*.jpg;*.jpeg;*.gif;*.bmp;*.png),*.jpg;*.jpeg;*.gif;*.bmp;*.png", , "Select a Picture")
        If picFile = False Then Exit Sub
        
        ' Step 2: Place the picture in cell E37 and resize it to the width = 36.50 and height = 86
        With ActiveSheet.Pictures.Insert(picFile)
            Dim N
            N = ActiveSheet.Pictures.Count
            Set WkRg = Cells(37, 5).Resize(6, 1)
            Set WkShape = ActiveSheet.Shapes.AddPicture(picFile, msoFalse, msoCTrue, WkRg.Left, WkRg.Top, WkRg.Width, WkRg.Height)
             Set WkRg = Worksheets("sheet1").Cells(13, 8).Resize(6, 3)
            Set WkShape = Worksheets("sheet1").Shapes.AddPicture(picFile, msoFalse, msoCTrue, WkRg.Left, WkRg.Top, WkRg.Width, WkRg.Height)
           ActiveSheet.Pictures(N).Delete
         
    
        End With
        
       End Sub
    
    
    
    Sub ImportGoodPicture2()
    Dim WkShape As Shape
        ' Step 1: Open a directory to select a picture on the PC to open
        Dim picFile As Variant
        picFile = Application.GetOpenFilename("Pictures (*.jpg;*.jpeg;*.gif;*.bmp;*.png),*.jpg;*.jpeg;*.gif;*.bmp;*.png", , "Select a Picture")
        If picFile = False Then Exit Sub
        
        ' Step 2: Place the picture in cell E37 and resize it to the width = 36.50 and height = 86
        With ActiveSheet.Pictures.Insert(picFile)
            Dim Nn
            Nn = ActiveSheet.Pictures.Count
            Set WkRg = Cells(37, 11).Resize(6, 1)
            Set WkShape = ActiveSheet.Shapes.AddPicture(picFile, msoFalse, msoCTrue, WkRg.Left, WkRg.Top, WkRg.Width, WkRg.Height)
             Set WkRg = Worksheets("sheet1").Cells(13, 3).Resize(6, 3)
            Set WkShape = Worksheets("sheet1").Shapes.AddPicture(picFile, msoFalse, msoCTrue, WkRg.Left, WkRg.Top, WkRg.Width, WkRg.Height)
           ActiveSheet.Pictures(Nn).Delete
        End With
    End Sub

  5. #5
    Forum Contributor
    Join Date
    03-27-2022
    Location
    MS, USA
    MS-Off Ver
    Microsoft 365
    Posts
    146

    Re: Two macros to insert and resize pictures interfering with each other

    Thank you for all your help and knowledge!

  6. #6
    Registered User
    Join Date
    09-01-2018
    Location
    USA
    MS-Off Ver
    365
    Posts
    96

    Re: Two macros to insert and resize pictures interfering with each other

    Sure, no problem
    Glad it works for you .

+ 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. Pictures Resize When Changing Page Breaks
    By Caldrumr1234 in forum Excel General
    Replies: 1
    Last Post: 06-12-2013, 11:42 AM
  2. Auto resize of pictures
    By Onesock in forum Excel General
    Replies: 7
    Last Post: 11-02-2012, 08:37 AM
  3. Insert/Delete Multiple Pictures but 1 or more pictures not available
    By MrNoodles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2012, 02:10 PM
  4. Copy and Resize Multiple Pictures then paste
    By Hlowmaster in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-22-2011, 05:53 PM
  5. Auto resize pictures in certain cells
    By mrggutz in forum Excel General
    Replies: 2
    Last Post: 08-24-2010, 07:33 PM
  6. Auto-Resize all pictures in worksheet
    By stevedes7 in forum Excel General
    Replies: 3
    Last Post: 12-05-2009, 07:12 AM
  7. Pictures resize and move at random?
    By Dazman22 in forum Excel General
    Replies: 2
    Last Post: 11-17-2009, 09:18 AM

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