Howdy. I have this little chunk of code that looks for a labeled object 'sku' on each page of a document and renames the page whatever the 'sku' is which could be something like A, B, C...etc. The thing is I did something wrong and I reckon it's simple for the real gurus so - help if you can.
1 2 3 4 5 6 7 8 9 10 11
Private Sub CommandButton3_Click() Dim p As Page, i As Integer, cur As Integer Set p = ActivePage cur = p.Index For i = 1 To ActiveDocument.Pages.Count ActivePage.Name = "__" & ActivePage.FindShape("sku").Text.Story Next i End Sub
Sub rename_pages_from_sku_text() Dim pageThis As Page Dim s_sku As Shape For Each pageThis In ActiveDocument.Pages Set s_sku = pageThis.FindShape("sku") If Not s_sku Is Nothing Then pageThis.Name = "__" & s_sku.Text.Story End If Next pageThis End Sub
Perfect. Now I just realized that I need to search only 'sku' labeled objects on Layer 1. There was a problem I had with the 'sku' object on the desktop layer so having the page renamer look at only Layer 1 would be great.
aaaaand I got it. Thanks again Eskimo.
Private Sub CommandButton3_Click()Dim pageThis As PageDim s_sku As Shape For Each pageThis In ActiveDocument.Pages Set s_sku = pageThis.Layers("Layer 1").FindShape("sku") If Not s_sku Is Nothing Then pageThis.Name = "__" & s_sku.Text.Story End If Next pageThisEnd Sub