July 18th, 2002, 01:16 PM
|
#1 (permalink)
| | Kawaru wa yo!
Join Date: Oct 2001 Location: Kingsford, MI
Posts: 16,132
| 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 |
| |
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? |
| |
July 18th, 2002, 02:13 PM
|
#3 (permalink)
| | Kawaru wa yo!
Join Date: Oct 2001 Location: Kingsford, MI
Posts: 16,132
|
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.
|
| |
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 ?? |
| |
July 18th, 2002, 02:43 PM
|
#5 (permalink)
| | Kawaru wa yo!
Join Date: Oct 2001 Location: Kingsford, MI
Posts: 16,132
|
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 |
| |
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  |
| |
July 18th, 2002, 03:22 PM
|
#7 (permalink)
| | Kawaru wa yo!
Join Date: Oct 2001 Location: Kingsford, MI
Posts: 16,132
|
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 |
| |
July 18th, 2002, 03:49 PM
|
#8 (permalink)
| | Kawaru wa yo!
Join Date: Oct 2001 Location: Kingsford, MI
Posts: 16,132
|
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 |
| |
July 18th, 2002, 04:08 PM
|
#9 (permalink)
| | Ultimate Member
Join Date: Oct 2001
Posts: 21,017
|
and if you
set a = nothing? |
| |
July 18th, 2002, 04:23 PM
|
#10 (permalink)
| | Kawaru wa yo!
Join Date: Oct 2001 Location: Kingsford, MI
Posts: 16,132
|
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.
|
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |