printing specific pages from Word via macro within IE

M

m1ke1ee

I posted this on microsoft.public.word.vba but got no response so
We have a system where Word 2000 Documents are being opened within
Internet Explorer 6.x. The URL is the full system path to the document,
so the users can edit the document and then save it back to the original
path specified in the URL... No Problem.

We recorded a VBA macro into the document to print pages in a specific
order. Under Word, the pages print in the order specified by the macro.
When the document is opened in IE, the macro executes, ( You can
watch it in the debugger...) but, the macro always prints out all pages
in the document sequentially, ignoring the specific pages or order
listed in the macro.

The saved macro uses Application.PrintOut with the chosen page sequence
in the Pages parameter.

If I execute the "File | Print... Menu Option" and specify my pages
manually then it appears to print correctly, however the sequence of
pages is distinct, and really long. The users will never remember the
sequence for each document type.

I searched the web and tried changing my .DOC options under file type
options in Windows Explorer, so Documents don't stay in the browser
window but open up instead in Word. (Advanced Button option). Now the
macros work and print the correct sequence, however the document
filename has been changed from the URL path to "Document in Internet
Explorer". Now the users can't update the file and save it back to it's
original location unless they navigate to the original directory and
overwrite the original file.

Is there anyway I can have my cake and eat it too?
 
M

m1ke1ee

Howard said:
Recorded macros rarely do what you expected.

See http://www.standards.com/index.html?MacroRecording.

You will need to modify the code of the macro to do the correct thing.

Thanks for Replying to my post Howard...

I totally agree with modifying the Recorded Macro to tune the performance.

The problem that I'm having is that the macro is only one method

Application.PrintOut

with it's associated parameters.

I tried modifying the code to Document.PrintOut assuming ( and probably
wrongfully ) that perhaps the Application Object was referencing the IE
Browser rather then the Word Document within.

The behavior is similar to pressing the Print Icon on the Toolbar. i.e.
"Print all pages in the document in the order saved."

Under the Debugger I can see the method being called, but it appears to
ignore the Pages Parameter when it runs.

Is there another VBA Object or Method that produces output to the printer?
 
M

Michael A. Lee

Howard said:
Recorded macros rarely do what you expected.

See http://www.standards.com/index.html?MacroRecording.

You will need to modify the code of the macro to do the correct thing.
Howard , I hope your watching this post because no one else seems to
provide a clue... and I mean anywhere on the Internet!

I created a small Word document 4 pages in length with the the words
"page {Pageno}" on each page. I then created the following code and
placed it in a new module in the document.

Sub UsePrintDialogToPrint()

With Dialogs(wdDialogFilePrint)
.Range = wdPrintRangeOfPages
.Pages = "3,2,3-4"
.Update
.Display
End With

End Sub

I researched and used the PrintDialog instead of the Document.PrintOut
method, because I pretty much beat the PrintOut method to the ground and
had to try something different.

I open the document in Word and the code works fine. Print Dialog comes
up and All I have to do is press [Enter] to submit the print job.

I'm estatic....

I open up Internet Explorer then open the document using the following url:

file:////C:\TestMacro.doc

The document opens in the Internet Explorer window. However, now when I
execute the macro I get

"run-time error 5148 - The number must be between 1 and 32767"

upon debuging, the cursor highlights the .Display line.

I can't find the error anyware on the Internet either. It appears that
VBA works differently when IE is involved.

I just need someone to confirm my issue, so I know I'm not going crazy.

Thanks in advance, to anyone who replies.
 
M

Michael A. Lee

Howard said:
Folkes watch, and respond to, threads on a volunteer basis.
Otherwise, if you casnnot figure it out yourself, you would need to pay
someone to help you.

Howard,

I do understand that this is entirely on a volunteer basis. And I
apologize to the community as a whole if this was not clear.

I actually mentioned you, by name, because I thought that it was kind
of you to provide your input.

I'm actually just trying to confirm that there is a problem if not a
bug when using a word document within IE.

I am not looking for a freebie... well maybe I am, but should we have
to pay someone to confirm that a bug exists? And if a bug exists, would
it not be helpful to others in the community if a workaround were
discovered and published so others could workaround the problem until
the bug is fixed?

I am skilled in several programming languages and appreciate what
Microsoft has done with the BASIC language as a whole. I particularly
like programming in VBA.

I am also thankful that you have provided so much of your self to the
industry that I love so much. (I reviewed your credentials at your website)

I am however saddened that your work as an independent contractor has
caused you to provide an answer such as "if you cannot figure it out
yourself, you would need to pay someone to help you"

If I ask questions on other newsgroups, the community at large is
helpful and prides itself in it's ability to help seasoned professionals
and newbies alike. I would think that a programming forum would be the
perfect place to isolate and identify a problem that may affect
countless others.

The main issue again... is:

WHY DO WORD MACROS BEHAVE DIFFERENTLY RUNNING WITHIN IE VS. NATIVELY
WITHIN WORD

Please try to remember, Howard, the good ole' days when if you had a
problem, you asked your partner, and the two of you worked on the
problem together, learned together and stayed up all night till it all
made sense.

I contemplated un-subscribing to this forum, but now realize that
there may be someone in my situation, who has a question out there that
I can answer.

This will be my last reply on this thread unless the matter deals
directly with the issue of Word Macros behaving differently when running
under Internet Explorer.
 
H

Howard Kaikow

Michael A. Lee said:
Howard , I hope your watching this post because no one else seems to
provide a clue... and I mean anywhere on the Internet!

Folkes watch, and respond to, threads on a volunteer basis.
Otherwise, if you casnnot figure it out yourself, you would need to pay
someone to help you.
 
H

Howard Kaikow

Michael A. Lee said:
WHY DO WORD MACROS BEHAVE DIFFERENTLY RUNNING WITHIN IE VS. NATIVELY
WITHIN WORD

one often has to write code differently for running outside of word.
each case has to be investigated separately.
 
M

Michael A. Lee

Howard said:
one often has to write code differently for running outside of word.
each case has to be investigated separately.

Thank you for your thoughtful response. You are obviously the
professional that I gathered you to be.

My concern is that there is no documented case for the error code 5148
and that the code behavior would be so different for the same VBA code.

My guess at this point is that the ActiveX code base for running Word
under Internet Explorer is significantly different from the Native Word
code base.

I would have thought that the ActiveX code is simply a wrapper to the
Word .dll's , but now that appears not to be the case.

I think, as you have said, that I may have to actually go external to
the both the IE and Word process and create a lava class (we're using
tomcat) to invoke the print operation as a separate operation outside of
word.

Thank you again for your input. I really hope to discuss Word, VBA and
other computing issues with you in the near future.

Sincerely,

Michael A. Lee
 
H

Howard Kaikow

Error 5148 is a common error.
Finding the cause can be easy, or very, ..., very difficult.
There's no simple answer.

Sometimes the problem may even be caused by yet another app getting in the
way.

For example see http://www.standards.com/index.html?PDFMakerandWordMacros
for tumblesaults I had to go through to eliminate a particular problem
caused by Acrobat. Took many, ..., many daze/hours to figure out that one.
 

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