Avatar of brothertruffle880
brothertruffle880Flag for United States of America asked on

Visio VBA - How to delete sheets 12 to the end

I would like to delete sheets 12 to the very last sheet in my collection of visio diagrams.
Can someone help me with the code on this?
I would like to keep sheets (i.e. diagrams)  1 through 11.
Microsoft VisioVisual Basic.NETVB Script

Avatar of undefined
Last Comment
Chris Bottomley

8/22/2022 - Mon
Chris Bottomley

Assuming the number og pages can vary but that you always want to delete the last 12 pages then for example:

Sub del12()
Dim doc As Document
Dim sh As Page

    Set doc = ActiveDocument
    If doc.Pages.Count <= 12 Then Exit Sub
    For x = 1 To 12
        doc.Pages(doc.Pages.Count).Delete False
    Next
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Scott Helmers

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Chris Bottomley

Yeah, I focussed on last 12 pages to delete NOT to keep only the first 11, doh!

Chris
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23