我想使用VBA在我的个人宏工作簿personal.xlsb中导出/维护/管理模块的文本文件备份。
我找不到一个在msdn上引用模块本身的对象库。有人能指出我正确的方向吗?
使用Excel 2013。
答案 0 :(得分:2)
您需要添加Visual Basic for Application Extensibility X.X参考;或者:
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
示例:强>
Sub Macromodule_copy1()
ThisWorkbook.VBProject.VBComponents("Macroos").Export "E:\Macroos.bas"
With Workbooks.Add
.VBProject.VBComponents.Import "E:\Macroos.bas"
End With
End Sub
更多示例和来源: Snb-Vba - 示例! -
答案 1 :(得分:0)
我只是使用以下代码将PERSONAL.xlsb的日期/时间戳副本保存到备份驱动器位置。
Sub PersonalBckup()
Const dstBak As String = "H:\PERSONAL MACROS\" 'change path to suit
Const dstBak2 As String = "D:\PERSONAL Macros\"
On Error Resume Next 'if either of the drives are not present, skip error.
Application.DisplayAlerts = False 'turn off warning popups
With Workbooks("PERSONAL.xlsb") 'name of your PERSONAL.xlsb file
.SaveCopyAs dstBak & "PERSONAL" & " as of " & Format(Now(), "YYYYMMDD_hhmmAMPM") & ".xlsb"
.SaveCopyAs dstBak2 & "PERSONAL" & " as of " & Format(Now(), "YYYYMMDD_hhmmAMPM") & ".xlsb"
.Save
End With
Application.DisplayAlerts = True 'Turn on warning popups
备份文件以日期/时间戳保存:“PERSONAL截至20180512_0136PM.xlsb”