Search code examples
vbaexcel

Export all modules from personal.xlsb


I would like to export/ maintain/ manage a text file backup of modules in my personal macro workbook personal.xlsb using VBA.

I cannot find an object library which refers to the modules themselves on msdn. Could someone point me in the right direction on this please?

Using Excel 2013.


Solution


  • You need to add Visual Basic for Application Extensibility X.X reference; or:

    Sub load_reference_1() 
    ThisWorkbook.VBProject.References.AddFromGuid "{0002E157-0000-0000-C000-000000000046}", 5, 3
    end sub
    
    Sub Load_reference_2() 
    ThisWorkbook.VBProject.References.AddFromFile "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"
    end sub
    


    Example:

    Sub Macromodule_copy1()
        ThisWorkbook.VBProject.VBComponents("Macroos").Export "E:\Macroos.bas"
         With Workbooks.Add
    
        .VBProject.VBComponents.Import "E:\Macroos.bas"
        End With
    End Sub
    

    Further examples and source: Snb-Vba -awesome examples!-