Solved

Visio  VBA - How to delete sheets 12 to the end

Posted on 2013-12-27
3
604 Views
Last Modified: 2013-12-30
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.
0
Comment
Question by:brothertruffle880
  • 2
3 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39742418
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

0
 
LVL 30

Accepted Solution

by:
Scott Helmers earned 500 total points
ID: 39742743
Chris definitely has the right idea but I think the logic isn't quite right. Try this to always leave the first 11 or fewer pages.
Sub Delete12Plus()
    
    Dim doc As Visio.Document
    Set doc = ActiveDocument

    While doc.Pages.Count >= 12
        doc.Pages(doc.Pages.Count).Delete False
    Wend

End Sub

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39743186
Yeah, I focussed on last 12 pages to delete NOT to keep only the first 11, doh!

Chris
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Calculate number of nights between two dates 5 53
Help with preventing selection from a combobox 11 34
get combo value in class 5 14
VB.Net. Reading xml value 6 29
Book Review: Using Microsoft Visio 2010 by Chris Roth   Disclaimer: The author of Using Visio 2010 is a friend and fellow Visio MVP. Whether you’re new to Visio or are upgrading to Visio 2010 from a previous version, you will find a lot to like…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question