View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
[email protected][_2_] jamesp@premiercs.co.uk[_2_] is offline
external usenet poster
 
Posts: 17
Default Using VBA to disable macros when opening files

I managed to get round the problem by creating a new instance of Excel to
open the files and disabling the macros there

Thanks for pointing me in the right direction


" wrote:

What I want to do is to audit files. However I don't want to start any
Auto_Open macros when I open a file. I have listed below a cut down version
of the macro I am using. When I open up the first file the macro just stops.
Any thoughts?


Sub AuditFiles()
Dim iFilename As Object
Dim lngAutomation As MsoAutomationSecurity

lngAutomation = Application.AutomationSecurity

For Each iFilename In Range("FilesToAudit")
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Workbooks.Open FileName:=iFilename, ReadOnly:=True, password:="",
updatelinks:=0
'test workbook

Application.AutomationSecurity = lngAutomation
Workbooks(iFilename).Close savechanges:=False
Next iFilename
End Sub

"helmekki" wrote:


Try this: it will do the job
place this code in the main file then open the other files, so the
codes in the other files will not be excuted.

the code will open the other files and prevent excuting the codes
inside them


Code:
--------------------
Sub Security()
Dim lngAutomation As MsoAutomationSecurity

With Application
lngAutomation = .AutomationSecurity
.AutomationSecurity = msoAutomationSecurityForceDisable
With .FileDialog(msoFileDialogOpen)
.Show
.Execute
End With
.AutomationSecurity = lngAutomation
End With

End Sub

--------------------


--
helmekki


------------------------------------------------------------------------
helmekki's Profile: http://www.excelforum.com/member.php...fo&userid=6939
View this thread: http://www.excelforum.com/showthread...hreadid=384353