Information générale
Catégorie:
Codage, syntaxe et commandes
Titre:
Launching Excel from within FoxPro
Greetings!
When running an .APP, I can successfully launch Excel under program control by issuing "RUN /N excel c:\temp". This loads an .XLS file called TEMP into Excel. (The temp file is created by FoxPro based on preferences in a grid.) Apparently, FoxPro recognizes Excel as a registered application, since I do not need to tell it exactly where EXCEL is; plus, no quotes are necessary.
However, if this command is excecuted within an .EXE, it generates an error: "RUN|! Command Failed." How can FoxPro "see" Excel from an .APP and *not* from an .EXE? Is there a reliable way to launch Excel without needing to know where it is (due to various installations)?
Plus, I need a solid way to test whether Excel is running before issuing the RUN command, otherwise, two copies will be loaded. Here is the code I came up with:
***********
set library to foxtools.fll
lnFindH = RegFn("FindWindow", "C@C", "I")
lcTitle = "Microsoft Excel - temp"
lnAppH = CallFn(lnFindH, 0, @lcTitle)
IF lnAppH != 0
lnFindH = RegFn("ShowWindow", "II", "I")
=CallFn(lnFindH, lnAppH, 2)
=CallFn(lnFindH, lnAppH, 3)
ELSE
RUN /N excel c:\temp
ENDIF
***********
This code appears to run well, depending on certain circumstances. Apparently, "lcTitle" must match exactly, otherwise another copy of Excel will load. If TEMP.XLS is open and its window is *not* maximized, Excel will be reported as "Microsoft Excel". However, if the file in Excel *is* maximized, Excel will be reported as "Microsoft Excel - temp". If all goes well, if Excel is already running, it will be activated (as with an Alt+Tab).
In summary, this whole process is very unreliable, and I need some help with two things:
1) How can Excel be reliably launched from within a FoxPro .EXE, without knowing the actual directory path?
2) How can the presence of Excel be detected, regardless of its file or window status?
I will appreciate any help. Thank you!
Michael Reynolds
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement