Open a workbook with macros disabled

Davers

Well-known Member
Joined
Sep 17, 2002
Messages
1,165
Hi everyone. I'm using VBA to open workbooks. I'd like to open them with their macros disabled. I'm currently using this:

Code:
Set wkbOne = Application.Workbooks.Open(fileToOpen, , ReadOnly)

To open them. I was thinking the readonly would disable macros, but it isn't. How could I do this?

Thanks,

Dave
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Good afternoon

'Fraid you can't. This is a security measure to stop people opening files via VBA and forcing the macros to run.

You could change the security settings to high, that would stop the macros running, but you'd have to use SendKeys to do so - bit of a clunky workaround but it's the only way...

HTH

DominicB
 
Upvote 0
That's kind of what I thought. I already had a workaround, I'm just deleting the before close event in the workbook. That's the code that was causing me troubles. In my case, I can do that because it's no longer needed....The report is only run once for each day from a template, then it is saved in a folder with the date it belongs to. The code is no longer needed after the day is done, so I use this:

Code:
Set VBCodeMod = ActiveWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule

    With VBCodeMod
        StartLine = .ProcStartLine("Workbook_BeforeClose", vbext_pk_Proc)
        HowManyLines = .ProcCountLines("Workbook_BeforeClose", vbext_pk_Proc)
        .DeleteLines StartLine, HowManyLines
    End With

to delete the "BeforeClose" event....

Thanks for the help and have a good day,

Dave
 
Upvote 0

Forum statistics

Threads
1,212,931
Messages
6,110,745
Members
448,295
Latest member
Uzair Tahir Khan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top