+ Reply to Thread
Results 1 to 15 of 15

Hide command button behind pic

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-07-2009
    Location
    Hemet, CA
    MS-Off Ver
    Office 2007 Professional
    Posts
    111

    Cool Hide command button behind pic

    I have a command button that is within a cell that when selected it insert a picture, the problem I have is when picture is in selected cell (same as command button) I can still view the command button from behind. I set the picture to “view from front” and Command button to “view from rear” but it doesn’t solve anything. I also have the command button checked to not print. Any ideas………………..

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Hide command button behind pic

    Hello ABabeNChrist,

    Do you want to hide the button, make it invisible, or just keep the button behind the picture?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    09-07-2009
    Location
    Hemet, CA
    MS-Off Ver
    Office 2007 Professional
    Posts
    111

    Cool Re: Hide command button behind pic

    Quote Originally Posted by Leith Ross View Post
    Hello ABabeNChrist,

    Do you want to hide the button, make it invisible, or just keep the button behind the picture?
    Hi Lieth Ross
    I want the command button to be visible to use, but yet not printable, and once picture is selected the command button goes behind picture, and not visible view. I don’t want command button to be removed, just in case wrong selection was made, that way picture could be deleted and then reuse command button once more to make correct selection. Here is the code I use to inset and size picture.
    And yes “just keep it behind picture”
    And by the way I’m using Excel 2007
        Dim PicLocation As String
        Dim MyRange As String
        
        ActiveSheet.Range("B1").Select
        MyRange = Selection.Address
    
        PicLocation = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp), *.jpg;*.bmp", Title:="Browse to select a picture")
        
        If PicLocation <> "False" Then
            ActiveSheet.Pictures.Insert(PicLocation).Select
        Else
            Exit Sub
        End If
        
        With Selection.ShapeRange
            .LockAspectRatio = msoTrue
            If .Width > .Height Then
                .Width = Range(MyRange).Width
                If .Height > Range(MyRange).Height Then .Height = Range(MyRange).Height
            Else
                .Height = Range(MyRange).Height
                If .Width > Range(MyRange).Width Then .Width = Range(MyRange).Width
            End If
        End With
        
        With Selection
            .Placement = xlMoveAndSize
            .PrintObject = True
        End With
        
        Range("A1").Select

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Hide command button behind pic

    Hello ABabeNChrist,

    Is the picture going into cell "B1"? Is the CommandButton located in cell B1 also?

  5. #5
    Forum Contributor
    Join Date
    09-07-2009
    Location
    Hemet, CA
    MS-Off Ver
    Office 2007 Professional
    Posts
    111

    Re: Hide command button behind pic

    Hi Leith Ross
    Is the picture going into cell "B1
    Yes
    Is the CommandButton located in cell B1
    Yes

  6. #6
    Forum Contributor
    Join Date
    09-07-2009
    Location
    Hemet, CA
    MS-Off Ver
    Office 2007 Professional
    Posts
    111

    Re: Hide command button behind pic

    Any suggestion how I may achieve this.....

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Hide command button behind pic

    Hello ABabeNChrist,

    Here is the amended version of the macro...
    Sub ResizePicture()
    
      Dim Pic As Excel.Picture
      Dim PicLocation As String
      Dim MyRange As Range
        
        Set MyRange = Range("B1")
        PicLocation = Application.GetOpenFilename(FileFilter:="Pic Files (*.jpg;*.bmp), *.jpg;*.bmp", Title:="Browse to select a picture")
        
        If PicLocation = "False" Then Exit Sub
        
        Set Pic = MyRange.Parent.Pictures.Insert(PicLocation)
        
          With Pic.ShapeRange
            .Left = MyRange.Left
            .Top = MyRange.Top
            .LockAspectRatio = msoFalse
            .ZOrder = msoBringForward
            If .Width > .Height Then
               .Width = MyRange.Width
               If .Height > MyRange.Height Then .Height = MyRange.Height
            Else
                .Height = MyRange.Height
                If .Width > MyRange.Width Then .Width = MyRange.Width
            End If
          End With
        
        With Pic
            .Placement = xlMoveAndSize
            .PrintObject = False
        End With
        
        Range("A1").Select
        
    End Sub
    Last edited by Leith Ross; 01-15-2010 at 09:53 PM. Reason: Added ZOrder command

  8. #8
    Forum Contributor
    Join Date
    09-07-2009
    Location
    Hemet, CA
    MS-Off Ver
    Office 2007 Professional
    Posts
    111

    Re: Hide command button behind pic

    Hi Leith Ross
    i just tried the code and I got an error on this line

    .ZOrder = msoBringForward

    Compile error
    Argument not optional

    I am using Excel 2007 if that make any difference

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Hide command button behind pic

    Hello ABabeNChrist,

    Sorry about that. Just force of habit to add an equal sign. The line should read...
      .ZOrder  msoBringForward

  10. #10
    Forum Contributor
    Join Date
    09-07-2009
    Location
    Hemet, CA
    MS-Off Ver
    Office 2007 Professional
    Posts
    111

    Re: Hide command button behind pic

    OK the picture was inserted in correct cell and the height was correct but the width was too narrow.
    I have a JPG that show picture to the left using new code. even when I try to expand the picture it still does not hide command button (picture to the right).
    and I also set the .PrintObject = False to True
    Attached Images Attached Images

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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