[Solved] Create new page with VBA, but stop if named the same

Started by SubPlanner, December 18, 2015, 02:06:14 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yacine

Yacine

wapperdude

@ Yacine

That's cool.

It's a difference in "logical" philosophy.  What you say is true.  The code searches through the pages collection, and if "New page" doesn't exist, then, by reasoning, then "New page" is not a page.  My reasoning goes like this, the code searches thru the pages collection, if "New page" is found, then, it exists, and that's the test.  If it doesn't, then, the last page found, IS a page, and is, the last page (not that it matters, it just needs to be some page).  By default, "New page" doesn't exist.  It's the same.  I just feel, that when searching thru a page collection, you ought to find a page, whether or not it's the specific page desired.  The function already does the testing, so, there's no extra execution "cost". 

Again, it's just a matter of philosophy.  I just leveraged the results of your "function" within the function.  Many ways to kill the coding cat.  Many ways to be satisfied and bring it back.

Anyway, happy holidays, merry Christmas, if you prefer.   ;D 

wapperdude
Visio 2019 Pro

Yacine

#17
Aaaaah, OK! It's Christmas.
A happy Christmas to you, your family and all the other members of the forum.
This reminds me on having to prepare something for the occasion.

Yacine
Yacine

SubPlanner

Thanks and Merry Christmas to you both. And Surrogate also, you helped me get the ball rolling.

SubPlanner

SubPlanner

#19
I have a variation of code that is a little mix of help from you guys, thanks for that.
Now I need help addressing the upper case vs. lower case situations.

See my code herein:

SubPlanner


Private Sub CommandButton2_Click() '1 of 3 new page code
If Me.NewTabName = "" Then
    MsgBox "Need a Tab Name.", vbOKOnly + vbInformation, "Page Name Detector"

ElseIf Me.NewTabName > "" Then
   Call newPage1
End If
End Sub

Function newPage1() '2 of 3 new page code
   Dim vsoPage1 As Visio.Page
   Dim pg As Page
   For Each pg In ActiveDocument.Pages
     
   If pg.Name = Me.NewTabName Then
MsgBox "Named the same as an exsiting page. Create a New tab Name", vbOKOnly + vbInformation, "Page Same-Name Detector"

Exit Function

End If
   Next pg
Call newPage2
End Function

Function newPage2() '3 of 3 new page code
  Dim vsoPage1 As Visio.Page
  'Dim pg As Page

Set vsoPage1 = ActiveDocument.Pages.Add
  vsoPage1.Name = Me.NewTabName
  Application.ActivePage.BackPage = "Template"
  Me.NewTabName = ""
End Function