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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

shellexecute() printing

Status
Not open for further replies.

Talbess

Programmer
Apr 29, 2006
17
AU
Hi, I am trying to use shellexecute() in VFP6 to print MSWord documents stored on a web server. If a document is stored on a local drive, shellexecute() will happily open or print the document, but if it is stored on a web server shellexecute() will open the document without problems but if I try to use shellexecute() to print then it always returns a value of 5 (Attempt was made to dynamically link to a task, or there was a sharing or network-protection error.)

I have placed the following document on my web site for testing:
Can anyone suggest a fix or another way to print documents on a web server.
 
Talbess,

Presumably, you are passing a URL as the third parameter to ShellExecute(). If so, ShellExecute() isn't operating on the Word document. It's opening a browser session, which in turn is trying to retrieve the document.

That's no problem if you simply want to open the document. The browser knows how to do that. But you can't command the browser to print the document within Word (at least, that's my understanding).

One solution might be to instantiate an instance of the browser control as a COM object. That will let you open the Word document in the browser. Then call the object's ExecWB method to print it.

Alternatively, can you give ShellExecute() a path to the document's physical location (as opposed to a URL)? That would enable you to print directly via ShellExecute().

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Mike, thanks for your reply.
I can't reach the documents by physical location as they are located on a document server and direct access to files is not supported, so I have to use a URL.

I'd like to try your suggestion to instantiate an instance of the browser control as a COM object, open the Word document in the browser, then call the object's ExecWB method to print it.

This looks a bit complicated so it might take me a week or so to figure out how to do the two steps as a background task, but thanks again for pointing me to a possible solution.
 
Try opening the document in MS Word from the web server. You may have to supply a username and password.
 
Thanks Cricket, but there is no problem opening a document, the problem is background printing the document.
 
Talbess,

You might try something like this (off the top of my head, and not tested):

Code:
loBrowser=CREATEOBJECT("internetexplorer.application")
loBrowser.Navigate2("[URL unfurl="true"]http://www.somewebsite/mydoc.doc")[/URL]
loBrowser.ExecWB(6, 1)
loBrowser.Quit

In case you're wondering, that (6, 1) means that "Print" is the 6th command on the 1st menu in IE.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
You're a legend Mike, those four lines are the bit that would have taken me a week.

I'm bogged down with some urgent work for a few days but I'll be back on it when I get a bit of spare time.
 
Talbess

One thing you may need to alter is the margins, etc, set for Internet Explorer as they will apply to any document printed this way suggested by Mike.

If you go to Page Setup in Internet Explorer, by default, you will have a header, footer, and margins for all four elements.

Whilst you can set them in Internet Explorer, you may also need to reset them after printing.

This can be done programmatically through the registry - if you need help with this aspect please advise.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
That couple of days turned into a couple of months.....
but I'm back on it now.

Mike's Code:
loBrowser=CREATEOBJECT("internetexplorer.application")
loBrowser.Navigate2("loBrowser.ExecWB(6,1)
works (of course) BUT the IE print function brings up the print dialog.
I want to do background printing so I don't want the dialog.
There is a print icon on IE6 that doesn't bring up the dialog, does anyone know how I can print from IE without the dialog using the VFP Browser interface?

Happy Easter!
 
I found the answer with some googling...

loBrowser.ExecWB(6,-1) prints without the print dialog.

Regards
 
Instead of using ShellExecute, could you use:

Code:
objWord=CREATEOBJECT("Word.Application")
objWord.Documents.Open("[URL unfurl="true"]http://www.mainplan.com/8ways.doc")[/URL]
objWord.PrintOut
objWord = .null.
RELEASE objWord


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Thanks Dave, this is a bit more eloquent than always using internet explorer but I have to be able to print anything (pdf's, gifs, bmps, excel etc

Those MS application objects are all different but its worth using for Word and Excel as these are the most common

My code is now looking like this (still using shellexecute() for files that have a UNC reference)
Code:
* DRAWLOCB contains contains links from one table (BACKLOG) to the actual document in table DRAWING
* BACKLOG->DRAWLOCB->DRAWING   DRAWLOCB is eof() if there are no documents to print
* Mlink is the document link which may be [URL unfurl="true"]http://www.whatever.com/document.doc[/URL] or \\servername\sharename\document.doc
* There may be multiple documents of any conceivable format to print 
If !eof('DRAWLOCB')
* need to create IE object early because its slow
	loBrowser=CREATEOBJECT("internetexplorer.application")
* timer for IE operations
	nMax=190
	Do while alltrim(DRAWLOCB.joblink)==ALLTRIM(BACKLOG.joblink)
		Mlink=alltrim(drawing.link)
		Do case
		Case atc('.doc',Mlink)>0
			loWord=CREATEOBJECT("Word.Application")
			loWord.Documents.Open("Mlink")
			loWord.PrintOut
			loWord = .null.
			Release loWord
		Case atc('.xl',Mlink)>0
			loExcel=CREATEOBJECT("Excel.Application")
			loExcel.Workbooks.Open("Mlink")
			loExcel.Sheets(1).PrintOut
			loExcel = .null.
			Release loExcel
		Case atc('http',Mlink)>0
			nMax=1
			loBrowser.Navigate2(Mlink)
			Declare INTEGER Sleep IN WIN32API INTEGER nTimeout
			Do WHILE loBrowser.ReadyState # 4
				Sleep(100)
			Enddo
			loBrowser.ExecWB(6,2,0,0)
			Declare INTEGER Sleep IN WIN32API INTEGER nTimeout
			Do WHILE loBrowser.ReadyState # 4
				Sleep(100)
			Enddo
		Case file(Mlink)
			ShellExecute(0, "Print", Mlink, "", "", 0)
		Endcase
		Select DRAWLOCB
		Skip
	Enddo
	Declare INTEGER Sleep IN WIN32API INTEGER nTimeout
	Do WHILE loBrowser.ReadyState # 4.and.nMax<200
		Sleep(100)
		nMax=nMax+1
	Enddo
	loBrowser.Quit
Endif
 
Spot the bug.....

Open("Mlink") should be Open(Mlink)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top