简体   繁体   中英

copy paste XL to PPT with 2 ranges

Hello I am using VBA to loop for ranges and copy as picture and paste to PPT slide. I want to know is there possibility to include 1 more range to code. So VBA will copy paste 2 ranges as picture.

  1. range is in following code. Works perfectly fine.
  2. range is single cell ( B1 ) Can anyone give me solution how can I add multiple range ( as picture ) to the slide?
k = 1    
    For i = 6 To Cells(70, Columns.Count).End(xlToLeft).Column Step 10

        With Cells(70, i)
 
            .Resize(1, 10).CopyPicture Appearance:=xlPrinter, Format:=xlPicture    '<---- xlPrinter or xlScreen

                DoEvents
                DoEvents

                    .Offset(150, 0).PasteSpecial
                DoEvents
            DoEvents
        End With

 'Give the last pasted picture a name.
                ActiveSheet.Pictures(ActiveSheet.Pictures.Count).Name = "Segment" & k

    k = k + 1

The function .CopyPicture does not work on multiple ranges that aren't connected to each other - trying it would return the error message:

Run-time error 1004: this action won't work on multiple selections

So you'll need to execute a separate .CopyPicture for your separate Range (B1), maybe something like (details depending on what exactly you're trying to do):

With Cells(70, i)
    .Resize(1, 10).CopyPicture Appearance:=xlPrinter, Format:=xlPicture
    .Offset(150, 0).PasteSpecial
    Range("B1").CopyPicture Appearance:=xlPrinter, Format:=xlPicture
    .Offset(140, 0).PasteSpecial
End With

If you want the multiple ranges to return just one single image, you'll probably have to merge the resulting images in a separate step.

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