Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of ShellExecute Method 1

Status
Not open for further replies.

patelr

Programmer
Oct 10, 2002
17
CH
Hi,

I want to launch a word application to print a document which does not have .DOC extension, although it is a word document. I have tried using ShellExecute method unsuccessfully.

Can anyone help????

Thanks in Advance
 
There are some other shell commands that allow you to specify which application to use. You may want to look into one of those. I believe the shellexecute API uses the windows file extention associations to determine which app to open the file with. Thanks and Good Luck!

zemp
 
Try passing the name of the file to the word executable as the command line. I have Office 2000, and the path for the executable for Word is c:\Program Files\Microsoft Office\Office10\winword.exe. So, to open a file in Word using the Shell command from VB, I used the following line:

Shell """C:\Program Files\Microsoft Office\Office10\WINWORD.EXE"" ""c:\My Documents\MyDocument"""


Pay attention to the quotes. The path for the executable and the path for the document both need to be in quotes, and since I'm passing the command line as a string, I have to have the whole thing in quotes, and use quote-quote everywhere a quotation mark should be in the command line.

Hope this helps!
 
Thank you for quick response.

Hwoever, I can launch word application and the document, but i am trying to print this document without user intervention.
 
The only way I know to do that is to create an instance of the Word App inside of VB and manipulate it directly.

Set a reference to the Microsoft Word Object Library. Then you can create an instance of the app, open the file, and print it all from code, like so:

Private Sub Command1_Click()
Dim WordApp As Word.Application

Set WordApp = New Word.Application

WordApp.Documents.Open "c:\MyDocument"
WordApp.PrintOut

End Sub

Hope this helps!
 

Check out the ShellExecuteEx API with the action verb being "print". Just one caution: you will need to associate the extension of the file to the program you want to use.

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top