Copy Image from Clipboard into Excel in Certain Cells

ashani

Active Member
Joined
Mar 14, 2020
Messages
345
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I'm using the below formula and I want to paste image from clipboard in certain area - however when i do it, the image doesn't fit in that section properly and either shrinks so much or so little.

Also, if there is no image on the clipboard or text - then I want the message box pop up to say "nothing to copy".

Thank you for your help.

VBA Code:
Sub copy()
    Dim p As Picture
    Dim Target As Range
    
    Application.ScreenUpdating = False
ActiveSheet.Unprotect Password:="abc"

    Set p = ActiveSheet.Pictures.Paste
    Set Target = Range("B3:I26")
       
    With Target
        p.ShapeRange.LockAspectRatio = msoFalse 'Allows Proper Sizing
        p.Top = .Top
        p.Left = .Left
        p.Width = .Width
        p.Height = .Height
    End With

ActiveSheet.Protect Password:="abc", DrawingObjects:=False, contents:=True, Scenarios:=True


End Sub
 
you're amazing @rlv01 and the best - thank you so much
just one question on this - is it possible to have date & time of the copy next to the image or underneath - once click macro button it paste the object and put date & time ?
Thank you once again.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Code to do that is included:
VBA Code:
        With .Offset(.Rows.Count, 1).Resize(1, 1)     'modify to suit yourself
            .Value = CStr(VBA.Date & "   " & VBA.Time)
            .EntireColumn.AutoFit
        End With

but where it should be and how it should be formatted is so subjective that I think you need to experiment with it.
 
Upvote 0
agree but for some reason it's not coming up. Here is the screenshot - I'd like a date and time of paste in Column A11 for example.

1590108356801.png
 
Upvote 0
VBA Code:
    ActiveSheet.Range("A11").Value = CStr(VBA.Date & " " & VBA.Time)
 
Upvote 0
You're the best - thank you so much for all your help.
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,049
Latest member
THMarana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top