none
Using VBA How Do I Open A Workbook In Safe Mode, Compile it and Save it RRS feed

  • Question

  • I have code that will compile an active workbook. I would like to modify it to compile a workbook that has been opened programmatically in safe mode using VBA. I know that a <g class="gr_ gr_52 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del" data-gr-id="52" id="52">wb</g> opened in safe mode can't run procedures itself, but I am hoping it can have procedures run against it,  in this case, the Compile procedure and theAddModule procedure (run first) to ensure it is in a compile-ready state, then save and close it.

    Any help much appreciated!

    Private Sub CompileThisWorkbook() 'compile active workbook  'https://stackoverflow.com/questions/28001620/can-i-compile-vba-on-workbook-open    Dim objVBECommandBar As Object    Set objVBECommandBar = Application.VBE.CommandBars    Set compileMe = objVBECommandBar.FindControl(Type:=msoControlButton, ID:=578) '578 is the id of the drop down menu item "Compile VBAProject" under Debug in the VBE    compileMe.Execute End Sub    Sub AddModuleToProject() 'http://www.cpearson.com/excel/vbe.aspx        Dim VBProj As VBIDE.VBProject        Dim VBComp As VBIDE.VBComponent        On Error Resume Next        Set VBProj = ActiveWorkbook.VBProject        Set VBComp = VBProj.VBComponents.Add(vbext_ct_StdModule)       

    VBComp.Name = "NewModule"    End Sub    Sub DeleteModule()        Dim VBProj As VBIDE.VBProject        Dim VBComp As VBIDE.VBComponent        On Error Resume Next        Set VBProj = ActiveWorkbook.VBProject        Set VBComp = VBProj.VBComponents("NewModule")    VBProj.VBComponents.Remove VBComp    End Sub




       
    Tuesday, February 19, 2019 5:30 PM