Results 1 to 6 of 6

Thread: Resize Image To Excel Window Size And Scale To Fit Automatically

  1. #1
    Junior Member
    Join Date
    May 2016
    Posts
    5
    Rep Power
    0

    Lightbulb SOLVED - Resize Image To Excel Window Size And Scale To Fit Automatically

    Hello,

    Wanted to know if it's possible to use a Macro to Scale the image on a sheet to automatically resize when the excel program is large or small?

    John
    Last edited by jjfletcher; 05-16-2016 at 04:46 PM. Reason: SOLVED

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10

    Resize Image To Excel Window Size And Scale To Fit Automatically

    Welcome to ExcelFox jjfletcher

    What you have asked for is very much possible. There may be ways to hook the window using APIs, however if you want to do this using native VBA features in Excel, you will need to use Excel 2013 or above. The code below is just a sample to show you how this can be done in a rudimentary yet very effective way.

    Code:
    Private Sub Workbook_WindowResize(ByVal Wn As Window)
        
        With ThisWorkbook.Sheets(1).Shapes(1)
            .Width = Wn.VisibleRange.Width
            .Height = Wn.VisibleRange.Height
        End With
        
    End Sub
    Attached Files Attached Files
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Junior Member
    Join Date
    May 2016
    Posts
    5
    Rep Power
    0
    Excellent - This works perfect... Thanks.... This is ok fro all Excel programs over 2013 - will need to focus on a solution for under 2013 versions.

    Thanks Again....

    Best Regards,

    John

  4. #4
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Share with us if you find anything for lesser versions of Excel.
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  5. #5
    Junior Member
    Join Date
    May 2016
    Posts
    5
    Rep Power
    0
    Thanks Excel Fox,

    I most certainly will send up if I find anything for lesser versions of Excel

    John

  6. #6
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by Excel Fox View Post
    Welcome to ExcelFox jjfletcher

    What you have asked for is very much possible. There may be ways to hook the window using APIs, however if you want to do this using native VBA features in Excel, you will need to use Excel 2013 or above. The code below is just a sample to show you how this can be done in a rudimentary yet very effective way.

    Code:
    Private Sub Workbook_WindowResize(ByVal Wn As Window)
        
        With ThisWorkbook.Sheets(1).Shapes(1)
            .Width = Wn.VisibleRange.Width
            .Height = Wn.VisibleRange.Height
        End With
        
    End Sub
    Actually, your code works fine down to, at minimum, XL2003 (the earliest version I own)... sort of. There is a WindowsResize event in XL2003 and above, but the event only fires when the worksheet window is not maximized and your code works only when you resize a non-maximized worksheet window. Apparently, when the worksheet is maximized, it is a fixed size and resizing the workbook only exposes or hides portions of that maximized window.
    Last edited by Rick Rothstein; 06-12-2016 at 06:57 AM.

Similar Threads

  1. How To Create Medium Size Button In Excel Office Ribbon Tab
    By Ashu2021 in forum Excel Ribbon and Add-Ins
    Replies: 4
    Last Post: 05-12-2014, 11:36 AM
  2. All Excel Files Opening In The Same Window
    By Jorrg1 in forum Excel Help
    Replies: 1
    Last Post: 08-21-2013, 12:14 AM
  3. Replies: 17
    Last Post: 07-15-2013, 09:56 PM
  4. Replies: 2
    Last Post: 04-14-2013, 08:23 PM
  5. Replies: 2
    Last Post: 10-05-2011, 04:18 PM

Posting Permissions

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