+ Reply to Thread
Results 1 to 3 of 3

Auto Resize Pasted Picture to merged cell

Hybrid View

CyberPath Auto Resize Pasted Picture to... 04-14-2012, 02:45 PM
mrice Re: Auto Resize Pasted... 04-14-2012, 03:41 PM
CyberPath Re: Auto Resize Pasted... 04-15-2012, 07:13 AM
  1. #1
    Registered User
    Join Date
    01-28-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    11

    Auto Resize Pasted Picture to merged cell

    Hi... To ALL...

    I get one macro that insert picture from disk to selected cell, then auto resize that picture to merged cell size.

    But, now i intend to use that same code to PASTE a picture (from System Clipboard) then resize to merged cell size

    PASTING to selected merged cell, it works fine...
    But.. The resize,... Not that fine.

    Here is the code i intend to use;

    Private Sub CommandButton1_Click()
    Dim p As Picture
     Application.ScreenUpdating = False
     
     Set p = ActiveSheet.Pictures.Paste
    
    If Target.Cells.Count = 1 Then Set Target = Target.MergeArea
     With Target
     p.Top = .Top
     p.Left = .Left
     p.Width = .Width
      End With
    
    End Sub

    I get ERROr in this line;

    If Target.Cells.Count = 1 Then ...

    Can someone help me in this...

    THANKs

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Auto Resize Pasted Picture to merged cell

    Replace Target with Selection as you don't appear to have specified what range Target is?
    Martin

  3. #3
    Registered User
    Join Date
    01-28-2012
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Auto Resize Pasted Picture to merged cell

    Quote Originally Posted by mrice View Post
    Replace Target with Selection as you don't appear to have specified what range Target is?
    Yes, you are right, there is another part of the code, like this;

    Private Sub CommandButton3_Click()
    
     Dim myPicture As String, MyRange As Range
     myPicture = Application.GetOpenFilename _
     ("Pictures (.bmp; .gif; .jpg; .png; .tif),.bmp; .gif; .jpg; .png; .tif", _
     , "Select Picture to Import")
    
     Set MyRange = Selection
     InsertAndSizePic MyRange, myPicture
    End Sub
    
    
    Sub InsertAndSizePic(Target As Range, PicPath As String)
    
     Dim p As Picture
     Application.ScreenUpdating = False
     
     Set p = ActiveSheet.Pictures.Insert(PicPath)
    
     If Target.Cells.Count = 1 Then Set Target = Target.MergeArea
     With Target
     p.Left = .Left
     p.Width = .Width
      End With
    
    End Sub

    BUT, after some more research, i have come up with this;

    Sub InsertAndSizePic(Target As Range, PicPath As String)
    Dim p As Picture 
    With Selection 
        Set p = .Parent.Pictures.Paste 
        p.Top = .Top 
        p.Left = .Left 
        p.Width = .Width 
    End With
    End Sub
    Thanks your tip led me to investigate...

+ 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