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
Miscellaneous
Thread ID:
00700028
Message ID:
00700266
Views:
12
This message has been marked as a message which has helped to the initial question of the thread.
>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

Something like:
objExcel.Application.CommandBars.ActiveMenuBar.Controls("Tools").Controls("Macro").Controls("Macros...").Enabled=.f.

However I am afraid that even you disable macros, it still can be used from another open document (if any).

One of the solution is to remove macro from the document,
and do not allow user to replace document when saving.

Something like:

x=objExcel.Application.VBE.ActiveVBProject.VBComponents
x.Remove(x.Item("Module2"))
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform