Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a better way .... ?
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Is there a better way .... ?
Miscellaneous
Thread ID:
00700028
Message ID:
00700028
Views:
61
I have used the solution below to open an excel spreadsheet, disabling the macros.

Please tell me there is a better way !!!!!!!



*-- API decs
DECLARE INTEGER FindWindow IN Win32API STRING, STRING
DECLARE INTEGER SetForegroundWindow IN "User32.dll" INTEGER
declare keybd_event in Win32API integer, integer, long, long

*-- Declare objects
LOCAL loExcel AS Excel.Application,loTimer

*-- Instantiate our timer
loTimer = NEWOBJECT("cTimer")

*-- Instantiate our Excel instance
loExcel = NEWOBJECT("Excel.Application")

*-- Fire up the timer
*-- It will keep looking for the Excel instance and once
*-- found will disable the macros by "hitting enter"
loTimer.Interval = 150

*-- Open up the workbook
loExcel.Workbooks.Open("d:\development\excel\test.xls")

WAIT "Got past the opening and am ready for action" WINDOW

RETURN


DEFINE CLASS ctimer AS timer
PROCEDURE Timer

LOCAL lnHwnd

*-- Get the windows handle of the excel sheet
lnHWnd = FindWindow(0,"Microsoft Excel")
IF lnHWnd <> 0

*-- Make the excel sheet have the focus
=SetForegroundWindow(lnHWnd)
*-- Simluate hitting the enter key
=keybd_event(13,0,0,0)
*-- Simulate letting it up again !!!!
=keybd_event(13,0,2,0)
*-- Turn off this timer
this.Interval = 0
*-- Say bye bye
this.Release()
ENDIF
ENDPROC

PROCEDURE Release
*-- Get rid of itself once its job is done
RELEASE This
ENDPROC

ENDDEFINE
Cheers,
Jamie
Next
Reply
Map
View

Click here to load this message in the networking platform