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!

How to open Microsoft Word or Excel document from VFP6.0?

Status
Not open for further replies.

timmappa

Programmer
Jan 21, 2001
20
0
0
AU
Please help,

How to open Microsoft Word or Excel document from VFP6.0? I need to put this in coding. Is their any function or command? Open the Word application and existing word document?
 
Did I not see this question asked, and answered, already today?

Anyway... FOR AN EXISTING WORD DOCUMENT on a machine with Word installed and .doc files associated with it all you need is:

Code:
FUNCTION BROWSER
	PARAMETER m.FILENAME
	LOCAL LNRETVAL, LCOPERATION
	LCOPERATION = "Open"
	IF MYFILE(m.FILENAME)
		DECLARE INTEGER ShellExecute IN SHELL32.DLL ;
			INTEGER handle,;
			STRING @sFile,;
			STRING @lp,;
			STRING @DIR,;
			STRING @dir1,;
			INTEGER ncmd
		LNRETVAL = SHELLEXECUTE(0, LCOPERATION, m.FILENAME, "", "", 1)
	ELSE
		MESSAGEBOX("Unable to locate the web page:"+m.FILENAME,48,"Problem")
	ENDIF
	RETURN(.F.)

The above requires the function MyFile() - a variant on File() which isn't fooled by the current path setting...
Code:
FUNCTION MYFILE
	PARAMETER m.FILENAME
	PRIVATE m.FILENAME,m.FLG
	M.FLG = .F.
	IF !EMPTY(m.FILENAME)
		IF ADIR(TMPDIRFILES,m.FILENAME) > 0
			M.FLG = .T.
		ENDIF
	ENDIF
	RETURN(m.FLG)

All you need to do is pass the Browser function the fully specified path to the file of interest:

Code:
Browser("c:\myfolder\mydocument.doc")

or any other document with an appropriate file association:

Code:
Browser("c:\myfolder\mypdffile.pdf")
[/code]


Regards

Griff
Keep [Smile]ing
 
Hi Griff,

You are correct. I have asked this question before in “Microsoft: VFP -General Coding Issues Forum”, but I didn’t get answer. Dave Murphy, CEO asked me to shift this question to “Microsoft: VFP - Automation, Mail & 3rd Party Svcs forum”.

Thanks for very useful information.

Tim
 
Hi TimMappa

>> How to open Microsoft Word or Excel document from VFP6.0? <<

You can use automation like so:

Code:
loDoc = GETOBJECT( 'd:\MyFolder\MyDocument.doc' )
loDoc.Application.Visible = .T.

You can then use the Windows API to brind that window to the forground like so:

Code:
Declare Integer FindWindow IN Win32Api String, String
Declare BringWindowToTop   IN Win32APi Integer
Declare ShowWindow         IN Win32Api Integer, Integer

lcTitle = loDoc.Name + [ - ] + loDoc.Application.Caption
lnHWND = FindWindow( NULL, lcTitle )
BringWindowToTop( lnHWND )
ShowWindow( lnHWND, 3 )




Marcia G. Akins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top