0

I select and copy the cells C4:I26 when I click on a button copiar texto and I paste them as an image. This is already happening.

I need this image to have a certain hyperlink when I paste it (on Outlook). So a click on the image opens this website.

Sub copiar_texto()
    Sheets("Planilha2").Select
    Range("C4:I26").Select

    Application.CutCopyMode = False

    Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
    Selection.Copy
    
    Application.CutCopyMode = False

    Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap

    Sheets("Planilha1").Select
    Range("F34").Select

    ActiveSheet.Shapes.Range(Array("Rounded Rectangle 4")).Select

    Selection.OnAction = "copiar_texto"
    
    Range("H31").Select
    
    ActiveWindow.SmallScroll Down:=-30
End Sub
Community
  • 1
  • 1
Bia Souza
  • 11
  • 2
  • You may also want to read up on [How to avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba) – Siddharth Rout May 18 '21 at 21:58

1 Answers1

2

This will copy a range from Planilha2 to Planilha1 as a picture, and add a hyperlink to the copied shape. If I copy that and paste it into an Outlook mail, it arrives with the hyperlink intact.

Sub Tester()

    Dim shp As Shape
    
    Sheets("Planilha2").Range("C4:I26").CopyPicture _
                Appearance:=xlScreen, Format:=xlPicture
    
    With Sheets("Planilha1")
        .Paste
        Set shp = .Shapes(.Shapes.Count)
        .Hyperlinks.Add Anchor:=shp, Address:="http://www.google.com"
    End With
     
End Sub
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Hi! Thank you so much for your answer. I just have one question, sorry if it´s a silly one, I am really new at this. Do I replace my current code with this one? Or I just add it to it? Cause I need to copy these cells when I hit the button "copiar texto" that is on "Planilha1" – Bia Souza May 18 '21 at 21:44
  • You would assign "Tester" to your existing button. – Tim Williams May 18 '21 at 21:52