0

In Publisher, not VBA, I use the navigation pane to select page 5. Now, the work I do manually will apply to page 5. However, now I want to run a macro I wrote which will import, resize, label, etc. a batch of images. How do I make my macro recognize that I want those images imported onto page 5 (my current working page)?

I wrote my macro hardwired to page 2 (because I couldn't answer the above question): set pg = activedocument.pages(2)

I envisioned something like (but this doesn't work, of course): set pg = activedocument.selected.page

Similarly, after my macro runs, and it adds three new pages, I want the selected/active page to be the last page I added (e.g., page 9). How to do that? Again, I envisioned something like: activedocument.pages(9).select

Much thanks.

2 Answers2

1

The property that you found (helping me out, so thanks!) is for both getting and setting, but the trick is that you have to set it to a page, rather than trying to set it to a PageIndex ("ActivePage = 2")

ActiveDocument.ActiveView.ActivePage = yourPage;

For instance, you could go to the next page with:

pubApp.ActiveDocument.ActiveView.ActivePage = pubApp.ActiveDocument.Pages[pubApp.ActiveDocument.ActiveView.ActivePage.PageIndex+1];

...Just realised that you're asking about VBA rather than C#, so here are some VBA examples just for you:

GoToNextPage()
    ActiveDocument.ActiveView.ActivePage = ActiveDocument.Pages(ActiveDocument.ActiveView.ActivePage.PageIndex + 1)
End Sub

GoToPageTwo()
    ActiveDocument.ActiveView.ActivePage = ActiveDocument.Pages(2)
End Sub
Jbjstam
  • 874
  • 6
  • 13
0

Question 1 is answered:

Set p = ActiveDocument.ActiveView.ActivePage

Question 2 remains: How do I use vba to make active a new particular page? (i.e., i could use VBA such that the above would return to me a different page for "p"?) For a shape, I can say: "my_shape.select"; how do I do that for a page?