Solved

Visio  VBA - How to delete sheets 12 to the end

Posted on 2013-12-27
3
608 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article I’ll describe a mashup of containers and lists that meet a real-world need. Prior to reading this ar…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

751 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