Teach myself how to do a complex task?

G

Gilfner

I want to fill a page with lots of detailed objects and info, but I bet I can
figure out how to do it all by myself if someone can give me an example
script/program (VBA?) that would simply, in Pub2k (or 2003 if you're not
sure, or 2007 if you insist):

1. create new pub doc "pubdoc.pub" in current folder

2. set one layout guide (anywhere) in new pub

3. insert one .gif image from current folder into new pub, reduce size by
40%, and put at exactly _this_ coordinate.

4. There is a simple .XML file in the current folder. Select a particular
text string out of it (any), trim off the first 15 characters, and put them
in a newly-created text box (this font and size, etc), placed exactly _here_
in the pubfile.

5. Then close the file and prompt for a printout.

In other words, with this skeleton, I bet I could create the big thing. I
may need help with the looping structures, but I'll come back for that later.
(I could call this the "Stone Soup" method of programming! Except maybe it
doesn't work. :-(

I'm a middle school librarian, trying to create a kind of color coded spine
label to help reshelve books more efficiently, using standard mailing labels.

I haven't programmed Publisher before, but I know it's in there, just below
the surface. Thanks in advance for any help you can give. Craig Wilson,
craigw at fsusd.k12.ca.us
 
E

Ed Bennett

Gilfner said:
I want to fill a page with lots of detailed objects and info, but I bet I can
figure out how to do it all by myself if someone can give me an example
script/program (VBA?) that would simply, in Pub2k (or 2003 if you're not
sure, or 2007 if you insist):

Publisher 2000 is completely non-automatable (except in the sense that
you can write a separate program to send mouse and key commands).
Publisher 2002 was the first version to introduce VBA support and
programmability; the functionality is not great. Publisher 2003 has a
better (although still imperfect) object model.

I.e. if you're using Publisher 2000, you'll need to upgrade before we
can help you. (Obviously there's not much point in writing a complete
example for you without knowing you'll be able to use it.)
 
G

Gilfner

Ed, I have Pub2k at work, and I have Pub2003 at home. (Although my wife has
2007 on her laptop.) I'm very motivated to make this project work, because
Publisher is the only program I know well, and the only one I can picture it
with. You're right, I guess the first call I need to make is which version to
use. Will 2003 work nearly as well as 2007, or should I aim for 2007? Notice
I'm not interacting with the user at all. I'd just like to add a gif from the
folder, size it, then add a string from an .XML file (then repeat). I've used
Publisher since 1.0 on floppies, which I bought at Egghead Software in SF.
 
E

Ed Bennett

Gilfner said:
Ed, I have Pub2k at work, and I have Pub2003 at home. (Although my
wife has 2007 on her laptop.) I'm very motivated to make this project
work, because Publisher is the only program I know well, and the only
one I can picture it with. You're right, I guess the first call I
need to make is which version to use. Will 2003 work nearly as well
as 2007, or should I aim for 2007?

I think that 2003 and 2007 will perform equally well in this context.
I've used Publisher since 1.0 on floppies, which I
bought at Egghead Software in SF.

Awesome! (On an off-topic note, you don't still have that lying around,
do you? I'm trying to collect all the retail boxed versions of Publisher)
 
G

Gilfner

Mary,

Obviously, my "stone soup" ploy (or "nail soup" in some versions) didn't
work. :) I did use the reference you gave, but couldn't find a starting
point, like a limited tutorial. I'm sure I will be using the VBA help section
once I get a start, though. Perhaps I should have kept my request to just the
first item.
Craig
 
G

Gilfner

About two years ago I, too, started collecting all the retail boxed versions.
I re-purchased them all from ebay, and I was going to make an archive out of
them. I didn't finish the project, and I put them all in a big ziplock bag,
now in my shed somewhere. I wonder how many other publisher lovers have
contemplated the same project. I'll have to look around sometime and locate
them. Version 1 was 3-1/2 floppy only - very compact.
 
E

Ed Bennett

Gilfner said:
Ed, I have Pub2k at work, and I have Pub2003 at home. (Although my wife has
2007 on her laptop.)

You could approach this in two ways - from within Publisher or from
outside Publisher. The differences are ultimately not massive; from
within Publisher requires less additional software.

First of all you'd have to create a new subroutine to contain your code.
This is opened with:

Sub DoSomeStuff()

and ended with

End Sub

(Typing Sub DoSomeStuff and hitting return will fill this all in for you.)
1. create new pub doc "pubdoc.pub" in current folder

Just as when you are creating a document manually, this is accomplished
by first creating a new document, and then saving it.

' Creates a variable to hold a pointer to the new publication
Dim aPub As Document

' Creates the document and sets "aPub" to point to it
Set aPub = Application.NewDocument()

' Saves the document - can come later
aPub.SaveAs ThisDocument.Path & "pubdoc.pub"

(Anything after a ' sign is called a 'comment' and is ignored by the
interpreter.)
This last statement takes the path of the current document and adds the
new filename to the end. If the current document isn't saved, then the
Path property is an empty string, so the argument given to SaveAs is
simply the filename "pubdoc.pub", and then the document is put in
Publisher's default folder - typically the My Documents folder.
2. set one layout guide (anywhere) in new pub

I think you mean a ruler guide; layout guides are the ones that are at
fixed divisions (columns/rows) and at the specified margins.

Ruler guides are added on a page level. You can add them either to the
foreground page or to the master page (aka Background in Pub2k terms,
although Publisher 2003 and later have multiple master pages).

aPub.Pages(1).RulerGuides.Add 21, pbRulerGuideTypeHorizontal

To add it to the master page, replace Pages with MasterPages. The number
is the position of the guide from the top or left of the page, in
points. (1 point = 1/72 inch)
Replace pbRulerGuideTypeHorizontal with pbRulerGuideTypeVertical to get
a vertical guide.
3. insert one .gif image from current folder into new pub, reduce size
by 40%, and put at exactly _this_ coordinate.

' Create variable to point to inserted image
Dim anImage As Shape

' Insert image
Set anImage = aPub.Pages(1).Shapes.AddPicture _
(ThisDocument.Path & "FileName.gif", msoFalse, msoTrue, 45, 70)

' Resize image
anImage.Height = .6 * anImage.Height
anImage.Width = .6 * anImage.Width

(An underscore at the end of a line means that the interpreter carries
onto the next line rather than ending the statement at the end of the
line; you can use lines as long as you like in VBA, but not in newsgroups.)

The filename is FileName.gif, 45 is the Left co-ordinate, 70 is the Top
co-ordinate, both in points. Again, the current directory is taken from
ThisDocument.Path - the path to the current publication.

Notice that when the result of a function (e.g. AddPicture here) is
assigned to a variable (anImage here), the arguments must be put in
brackets. When it is discarded (like with RulerGuides.Add further up)
then the arguments must not be put in brackets.
4. There is a simple .XML file in the current folder. Select a
particular text string out of it (any), trim off the first 15
characters, and put them in a newly-created text box (this font and
size, etc), placed exactly _here_ in the pubfile.

I don't do XML; you'll have to ask in a VBA or VB6 newsgroup for that.
Presuming you have the text from the XML file in a String variable
called aString, then:

Dim aTextBox As Shape
Set aTextBox = aPub.Pages(1).Shapes.AddTextBox _
(pbTextOrientationHorizontal, 10, 20, 30, 40)
aTextBox.TextFrame.TextRange.Text = Mid(aString, 16)
aTextBox.TextFrame.TextRange.Font.Name = "Arial"
aTextBox.TextFrame.TextRange.Font.Size = 21
5. Then close the file and prompt for a printout.

As earlier, things have to be done in the order you'd do them in the UI.
I.e. you have to print, then close.

Publisher does not have an option to display the Print dialog; the only
option is a non-interactive print, using the method

aPub.PrintOut

This can be altered to contain a starting and finishing page number, a
file name for printing to file, a number of copies, and specifying
whether or not the output should be collated. The printer used will be
the system's default printer (Publisher 2007 includes additional options
here, including choosing the printer to use and specifying multiple
pages per sheet, etc., but this is still entirely non-interactive).

To close:
aPub.Close
 
G

Gilfner

Ed, it worked! It worked! (Why should I be surprised?)

Now can we do more? Huh? Huh? (Why can't a beginner ever just be grateful,
without asking for more?)

You've given me a great start, a toehold, just what I needed. In the
meanwhile, I'd gone and purchased a book for beginners, called "Absolute
Beginner's Guide to VBA" by Paul McFedries, from Amazon. When you buy it, you
are allowed, for an extra $2.50, to start reading it online while you wait
for it to arrive. So I read several chapters, and was ready for what you gave
me. It sounds like there's not much demand for Publisher programming, but
there is for me. I want to use it for Database output, which is what this
application really is. Is there a superior book on the subject? Or a
reference manual that substitutes well for MSDN (which I don't have, but with
intellisense, is probably not so necessary)?

Thanks again,
Craig

p.s. I went and searched for my pub archive stuff. I didn't find it yet, but
I'll keep looking. c.w.
 
E

Ed Bennett

Gilfner said:
I want to use it for Database output, which is what this application
really is.

One thing I meant to mention in my previous message, but forgot, was:
Have you considered using the Catalog Merge for this? Introduced in
Publisher 2003, it seems rather similar in functionality to what your
program is trying to accomplish.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top