home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 3129
Discussions: 188,375, Posts: 2,243,439, Members: 232,603
Old July 18th, 2002, 01:16 PM   Digg it!   #1 (permalink)
Kawaru wa yo!
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 16,132
Blog Entries: 7
Help: Print HTML docs w/VBA

Okay, here's the rundown, I've got a program that goes through an AutoCAD map and makes an HTML document list of all the data inside a certain block. What I would like to do is make a print function with the VBA that doesn't involve opening the page in a browser to print it AKA a print button.

So far, I've tried using the Microsoft Internet Controls reference, eg
Code:
    Dim a as WebBrowser
    a.Navigate sPath ' Path to HTML doc
    a.???
There doesn't seem to be a print function like one would expect (or at least like I was lead to believe).

Anybody got any ideas?

-Whir

Whir is offline   Reply With Quote
Old July 18th, 2002, 01:40 PM     #2 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,017
Well word can view html documents, have you tried using the word object? I would think it has a print method

Dim a as Application.Word I think it is?

vass0922 is online now   Reply With Quote
Old July 18th, 2002, 02:13 PM     #3 (permalink)
Kawaru wa yo!
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 16,132
Blog Entries: 7
Okay, here's what I've got now:

Dim a as New Word.Document
a.Application.Document.Open sDocument
a.PrintOut
a.Close

This yields a blank sheet of paper, although it did, in fact, open the document in Word (since I had it open). I specified the filename after PrintOut also, and it still yields a blank sheet. Hard to find a descriptive help on this pile...

-Whir

Edit: So does:
a.ActiveWindows.PrintOut

Maybe there's a field I should be filling in for the function? It's a lot less than specific in the help.


Last edited by Whir : July 18th, 2002 at 02:19 PM.
Whir is offline   Reply With Quote
Old July 18th, 2002, 02:38 PM     #4 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,017
hmmm

maybe set a specific object for the document

Set doc = a.application.document.open sdocument

doc.printout ??
vass0922 is online now   Reply With Quote
Old July 18th, 2002, 02:43 PM     #5 (permalink)
Kawaru wa yo!
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 16,132
Blog Entries: 7
Tried that too. Miraculously this works for printing:
Code:
Private Sub CommandButton1_Click()
    Dim a As New Word.Document
    
    a.Application.Documents.Open "D:\Run\WI1471-1339.htm"
    a.Application.PrintOut
    a.Close
End Sub
However... Unless the program has already run once, it won't close the program! I'm still playing with it, but so far not so good.

Then once I get it working, I need to make it print a whole direction. Fun with While Not.

-Whir
Whir is offline   Reply With Quote
Old July 18th, 2002, 03:17 PM     #6 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,017
Hmm if this is going to do a lot of work, better hope for no memory leaks I would assume there's a parameter you can pass to the open method so it doesn't show the GUI portion of WORD that would just get annoying and terribly slow.
Do you mean a whole directory?
If thats the case, then it gets easy you canjust use the folders and files collection in the scripting.filesystem object
vass0922 is online now   Reply With Quote
Old July 18th, 2002, 03:22 PM     #7 (permalink)
Kawaru wa yo!
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 16,132
Blog Entries: 7
Ya, I'm not really worried about the directory part. I just use sFile = Dir(*.htm) and While Not sFile = "".
I don't know if there's a setting to go non-GUI or not. If Word has opened once, it won't open the GUI, but if it's the first time, it opens it. Haven't been able to find a way to stop it yet. Argh.

Thanks for the help vass, wouldn't have gotten this far w/out it.

-Whir
Whir is offline   Reply With Quote
Old July 18th, 2002, 03:49 PM     #8 (permalink)
Kawaru wa yo!
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 16,132
Blog Entries: 7
Well, you can do the Visible:=False, but it then it leaves WINDWORD.EXE sitting in memory, and keeps the file locked, even though I've done a close on it. The lock isn't a big deal, but I can't go leaving the Word executable open, eating up memory. Arghness x 2.

-Whir
Whir is offline   Reply With Quote
Old July 18th, 2002, 04:08 PM     #9 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,017
and if you
set a = nothing?
vass0922 is online now   Reply With Quote
Old July 18th, 2002, 04:23 PM     #10 (permalink)
Kawaru wa yo!
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 16,132
Blog Entries: 7
Still leaves it open. I'm guessing because a = document, not the program itself. But if you do a as new Word.Application, there's no close method!

Maybe Word can be set up like AutoCAD so it's SDI and can only open one document at once? If you do a .close in MDI AutoCAD, it closes the map but leaves the program open. If you do a .close in SDI, it shuts down the program...

-Whir

Edit: Or I suppose I could use...

a.Application.Quit

<bashes head against desk>

Hah, get this, if I put that in there, it won't print!! It must send the quit too fast and not get the print command finished in time. Man this is just bizarre.

Last edited by Whir : July 18th, 2002 at 04:32 PM.
Whir is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2881)
The United States Debt (20)
Looks like Burris will get his Sena.. (7)
Upgrading RAM (5)
I think I just killed my computer w.. (24)
Folderchat Weekday thread (436)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (14)
Titan quest and Immortal Throne, an.. (17)
Recent Discussions
Help with an Ati Radeon HD 4850.. (23)
Laptop waking up itself (0)
CPU wont boot (3)
Best digital camera for under 2.. (13)
Building first computer, will t.. (2)
Folderchat Weekday thread (436)
get this error, "res://C:\.. (73)
Problem with boot and motherboa.. (0)
MS to offer free Windows 7 upgr.. (1)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 07:40 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28