Is it possible to get your VBA Project to save itself in code? Thank you, David
Hi David This one I've found a while ago... Modified version from Kevin Terry's function (posted 10/15/2002): '----------------------------------------------------------------------------- ' Exports all modules, classes and forms from project into a subdirectory with ' the name of the current version of project and current date. ' Necessary references: ' - Microsoft Visual Basic for Applications Extensibility ' - Microsoft Scripting Runtime ' Public Sub ProjectRevisionBackup() Dim vApp As VBIDE.VBE Dim vProj As VBProject Dim vComp As VBComponent Dim sPath As String Dim sProjPath As String Dim PrjNme As String Dim PrjVer As String Dim sFile As String Dim sProj As String Dim sCode As String Dim asFiles() As String Dim i As Integer Dim FilObj As FileSystemObject Dim DatObj As File Set vApp = Application.VBE Set FilObj = CreateObject("Scripting.FileSystemObject") PrjNme = "MyProject" 'Set to project name PrjVer = "1.01.03" 'Set to project version For i = 1 To vApp.VBProjects.Count If UCase(vApp.VBProjects(i).Name) = UCase(PrjNme) Then Set vProj = vApp.VBProjects.Item(i) sPath = vProj.BuildFileName sFile = FilObj.GetBaseName(sPath) sProj = sFile & ".dvb" sPath = FilObj.GetParentFolderName(sPath) End If Next i 'build path for version sProjPath = sPath sPath = sPath & "\VBA-v" & PrjVer & "-" & Format(Date,"mm-dd-yyyy") 'raise error for no path On Error Resume Next ChDir (sPath) 'make directory If Err.Number = 76 Then MkDir (sPath) Err.Clear On Error GoTo 0 'copy project file Set DatObj = FilObj.GetFile(sProjPath & "\" & sFile & ".dvb") DatObj.Copy sPath, True 'export all components For i = 1 To vProj.VBComponents.Count Set vComp = vProj.VBComponents.Item(i) sFile = vComp.Name 'test for type: Select Case vComp.Type Case vbext_ct_MSForm vComp.Export sPath & sFile & ".frm" Case vbext_ct_ClassModule vComp.Export sPath & sFile & ".cls" Case vbext_ct_StdModule vComp.Export sPath & sFile & ".bas" Case vbext_ct_Document vComp.Export sPath & sFile & ".cls" Case Else 'do nothing End Select Next MsgBox "Remember to manually compress the project file.", vbOKOnly, _ PrjNme & " " & PrjVer Set vApp = Nothing Set vProj = Nothing Set vComp = Nothing Set FilObj = Nothing Set DatObj = Nothing End Sub '----------------------------------------------------------------------------- Cheers
Thanks for that reply, Jürg I was hoping that there was some easy method in VBA that wouldn't require my user to check for the necessary references, but it looks like that may not be possible David