简体   繁体   中英

Paste an image from the Clipboard into Excel

I have an excel spreadsheet that I've built as a form, I need to add in a signature to several ranges on different tabs within the workbook.

I've got this code, which will paste from the clipboard on to my sheet, it seems to only want to paste in the top left corner of the sheet and doesn't want to resize to the values set.

How can I get it to paste where I want and to the size I want? From this I'm going to want to be able to copy this and paste into several other sheets with varying range locations

Sub Signatures()
    Sheets("MySheet1").Select
    Range("A11").Select
    ActiveSheet.Paste
    Selection.ShapeRange.ScaleHeight 0.8513513514, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.9399224806, msoFalse, msoScaleFromTopLeft 
End Sub

My process is, open the jpg file within paint make the selection to copy, click copy, go into the excel workbook andclick on the place signature button. I then want it to paste the copied signature into the location I want and size to the relevant size I will predetermine. What would be a better way to do this?

Save the JPG File. Let's say you saved it as "C:\\Signature.Jpg"

Try this code

Sub InsertSignatures()
    Dim ws As Worksheet
    Dim ImgPath As String
    Dim W As Double, H As Double
    Dim L As Long, T As Long

    Set ws = ThisWorkbook.Sheets("MySheet1")

    '~~> Change this to the releavnt pic file
    ImgPath = "C:\Signature.Jpg"

    With ws
        W = 100                  '<~~ Width
        H = 100                  '<~~ Height
        L = .Range("A11").Left   '<~~ Left Position for image
        T = .Range("A11").Top    '<~~ Top Position for image

        With .Pictures.Insert(ImgPath)
            With .ShapeRange
                .LockAspectRatio = msoTrue
                .Width = W
                .Height = H
            End With
            .Left = L
            .Top = T
            .Placement = 1
        End With
    End With
End Sub

OUTPUT

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM