Solved

Visio  VBA - How to delete sheets 12 to the end

Posted on 2013-12-27
3
595 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Periodically someone asks me whether there’s a way to automatically convert all of the pages in a Visio drawing to PowerPoint slides. There have even been a few times when I’ve wanted to do that myself but I never really had enough incentive to figu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now