×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Deleting all Visio Background pages with VBA

Deleting all Visio Background pages with VBA

Deleting all Visio Background pages with VBA

(OP)
Hello, I am trying to delete all background pages in Visio 2003 using the following code:
Sub DeleteBackGroundPages()

Dim MyPage As Page
For Each MyPage In ActiveDocument.Pages
'Test for a "Background" page here
If MyPage.Background = True Then
'Delete the page
MyPage.Delete True
End If
Next MyPage
End Sub

However when the code runs it only deletes a few pages at a time. For testing purposes, I used a document with ONE foreground page and FOUR background pages. On the first run of the procedure, TWO background pages were deleted, then next run deleted another page and finally on the third run, the fourth background page was deleted. I have tried it using "False" for the page reordering as well with no success.

Any advice would be greatly appreciated.
Thanks in advance.
Mark

RE: Deleting all Visio Background pages with VBA

Just a thought. I've never used VBA in Visio, but often encounter similar problems when deleting in other MS applications. It seems to lose the count as it is deleting. Try counting backwards:

CODE -->

Dim MyPage As Page
Dim P as Integer
For P=ActiveDocument.Pages.Count to 1 step -1
If MyPage.Background = True Then
'Delete the page
MyPage.Delete True
End If
Next P 

Don't know about the pages collection, so you may need to count to 0 rather than 1. As I say - just a thought - I may be completely wrong pipe

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close