Print output file in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have looked through the previous posts but can't find the answer to my
problem. I have created a Word file in VBA and saved it on the network via
something similar to this code:

Open strPath & strFileName & ".doc" For Output As #1
Print #1, strText1
Print #1, strText2
Close #1

Once this file is created, how do I send it to the default printer without
user intervention?

Thanks,
Melanie
 
Hi Melanie,

How can I put this tactfully? If you were the sort of programmer who can
create a Word document by passing two strings to Print #, you probably
wouldn't be asking how to print a Word document under program control.

So I'll assume that what you're actually creating is a text file with a
..doc extension. You can send this to the printer via Notepad with
something like this

Dim strPrtCmd As String

strPrtCmd = Environ("WINDIR") & "\system32\NOTEPAD.EXE /p " _
& strPath & strFileName & ".doc"
Shell strPrtCmd
 
While I appreciate the response, I don't see how judging me or assuming
anything about my situation actually helps answer my question.

So, if anyone else could offer some assistance, I would greatly appreciate it.
 
I'm sorry that you've taken offence. If you really are concatenating two
strings and creating valid Word binary files, permit me first to take my
hat off to you and then to refer you to
http://support.microsoft.com/kb/210030 (though I'd recommend replacing
"WordObj.Quit" with "WordObj.Quit False").
 

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

Back
Top