Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Visio  VBA - How to delete sheets 12 to the end

Posted on 2013-12-27
3
Medium Priority
?
617 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 31

Accepted Solution

by:
Scott Helmers earned 2000 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

718 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