Macro with PrintOut method

T

Tan

I'm trying to create a macro using the PrintOut method but it won't work if I
just want a certain page. It always prints out the whole document. I'm
using the syntax suggested and it still won't accept it...Any ideas?
 
E

Ed Bennett

Tan said:
I'm trying to create a macro using the PrintOut method but it won't
work if I just want a certain page. It always prints out the whole
document. I'm using the syntax suggested and it still won't accept
it...Any ideas?

Which version of Publisher are you using?
 
T

Tan

I'm not sure it's been installed and when looking in the Microsoft website,
it says no download is available for Publisher. Could that also be why I
can't record macros in Publisher 2003???
 
E

Ed Bennett

Tan said:
I'm not sure it's been installed and when looking in the Microsoft
website, it says no download is available for Publisher. Could that
also be why I can't record macros in Publisher 2003???

Check Help > About. This will say "SP1" if you have SP1.

No version of Publisher yet has a Macro Recorder, unfortunately. If you
want one, here's the place to look:

How to Contact the Microsoft Wish Program
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q114491

Can you post the line of code you are using with the PrintOut method?
 
T

Tan

I am using the SP1 with the software.

The code is the following:

Sub hastext()
With ActiveDocument.Pages(1).Shapes(1).TextFrame
If .hastext Then ActiveDocument.PrintOut (1,1)
End With
End Sub

It won't let me write the conditions...
Thank you.
 
E

Ed Bennett

Tan said:
If .hastext Then ActiveDocument.PrintOut (1,1)

HasText does not return a boolean variable, so I'm not sure whether you are
able to use it in the same way in this circumstance.

What happens if you replace If .HasText with If .HasText = msoTrue?

Are you calling this from an add-in or from a macro?
 
T

Tan

the hastext is working fine. I actually took it from the VBA help in Publisher.
And I also found the solution to my problem. It was the syntax of the
printout method. Thank you very much for your help.
 
E

Ed Bennett

Tan said:
the hastext is working fine. I actually took it from the VBA help in
Publisher. And I also found the solution to my problem. It was the
syntax of the printout method. Thank you very much for your help.

Oops - sorry, I misread your code :(

Glad to hear that you fixed your problem - feel free to post the corrected
code so that other future users of this group may benefit.
 
T

Tan

For i = 1 To n
With Documents("x.pub").Pages(i).Shapes(1).TextFrame
If .HasText Then
Documents("x.pub").PrintOut From:=i, To:=i
Else
Publisher.Application.Open Filename:="C:\y.pub"
Documents("y.pub").PrintOut From:=i, To:=i
End If
End With
Next i
 
E

Ed Bennett

Tan said:
Documents("x.pub").PrintOut From:=i, To:=i

This is a correct syntax, but the syntax you were using previously was also
correct.

I am at a loss as to why your old syntax didn't work, but I'm glad you've
worked around your problem.
 

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