FOR EACH WS starts at the very last sheet. Why?

VBAWannabee2

New Member
Joined
Feb 23, 2022
Messages
28
Office Version
  1. 2010
Platform
  1. Windows
Hi all!

My concern is what exactly the thread title is.
This is the code that I used to copy excel data then paste it on PPT but it starts the loop at the very last sheet.
Why is that? Appreciate the help in advance!

VBA Code:
Sub CreateNewPres()

    Dim ppt As PowerPoint.Application
    Dim pres As PowerPoint.Presentation
    Dim sh As PowerPoint.ShapeRange
    Dim sl As PowerPoint.Slide
    Dim ws As Worksheet
    
    Set ppt = GetObject(Class:="Powerpoint.Application")
    Set pres = ppt.Presentations("TESTFILE - Copy.pptx")

For Each ws In ActiveWorkbook.Worksheets

If ws.Visible = True Then

    Set sl = pres.Slides.Add(3, ppLayoutBlank)

    ws.Range("A1:D8").Copy

    Set sh = sl.Shapes.PasteSpecial(ppPasteEnhancedMetafile)
    
    'sh.Top = 66
    'sh.Left = 152
    sh.LockAspectRatio = msoFalse
    sh.ScaleHeight 1.24, msoTrue, msoScaleFromMiddle
    sh.ScaleWidth 1.33, msoTrue, msoScaleFromMiddle
    
End If

Next ws

MsgBox "Process done!"

End Sub
 
Try
VBA Code:
Set sl = pres.Slides.Add(pres.Slides.Count - 3, ppLayoutBlank)
It's so simple yet I can't think of it. LOL. Thanks Skyybot! Adjusted it to -2 though and it works well now. Thanks a lot. You too RoryA!!
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,215,201
Messages
6,123,617
Members
449,109
Latest member
Sebas8956

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