Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Visio  VBA - How to delete sheets 12 to the end

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

926 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