|
| 1 | +Attribute VB_Name = "VBAandXML" |
| 2 | +Option Explicit |
| 3 | + |
| 4 | +Sub exportVbaAndXMLCode() |
| 5 | + |
| 6 | + Dim wb As Workbook |
| 7 | + Set wb = ActiveWorkbook |
| 8 | + |
| 9 | + wb.Save |
| 10 | + |
| 11 | + Call Build.exportVbaCode(wb.VBProject) |
| 12 | + Call XMLexporter.unpackXML(wb.name) |
| 13 | + |
| 14 | + 'Delete the VBProject bin file |
| 15 | + 'On Error Resume Next |
| 16 | + 'Delete files |
| 17 | + Dim FSO As New Scripting.FileSystemObject |
| 18 | + FSO.DeleteFile wb.Path & "\src\" & wb.name & "\XMLsource\xl\vbaProject.bin", True |
| 19 | + 'On Error GoTo 0 |
| 20 | + |
| 21 | + MsgBox "Successfully exported VB code and XML content." |
| 22 | +End Sub |
| 23 | + |
| 24 | +Sub ImportVbaAndXMLCode_ActiveWorkbook() |
| 25 | + |
| 26 | + Call ImportVbaAndXMLCode |
| 27 | + |
| 28 | +End Sub |
| 29 | + |
| 30 | +Sub ImportVbaAndXMLCode(Optional ByVal FileFolderPath As String) |
| 31 | + |
| 32 | + Dim wb As Workbook |
| 33 | + Dim oFileName As String, nFileName As String, nShortFileName As String, oFileFolderPath As String |
| 34 | + |
| 35 | + If FileFolderPath = vbNullString Then |
| 36 | + Set wb = ActiveWorkbook |
| 37 | + oFileFolderPath = wb.Path |
| 38 | + oFileName = wb.FullName |
| 39 | + nShortFileName = wb.name |
| 40 | + wb.Close |
| 41 | + Else |
| 42 | + oFileFolderPath = Left(FileFolderPath, InStr(FileFolderPath, "\src") - 1) |
| 43 | + oFileName = Replace(FileFolderPath, "\src", "") |
| 44 | + nShortFileName = Split(FileFolderPath, "\")(UBound(Split(FileFolderPath, "\"))) |
| 45 | + End If |
| 46 | + |
| 47 | + Dim nwb As Workbook |
| 48 | + Dim ErrFlag As Boolean, ErrMsg As String |
| 49 | + ErrFlag = False |
| 50 | + ErrMsg = "" |
| 51 | + |
| 52 | + 'Ask the user to confirm |
| 53 | + Dim ireply As Variant |
| 54 | + ireply = MsgBox(prompt:="Are you sure that you want to overwrite " & nShortFileName, Buttons:=vbYesNo, title:="Decision") |
| 55 | + |
| 56 | + If ireply = vbYes Then |
| 57 | + 'Do nothing (Continue) |
| 58 | + ElseIf ireply = vbNo Then |
| 59 | + Exit Sub |
| 60 | + Else 'They cancelled (VbCancel) |
| 61 | + Exit Sub |
| 62 | + End If |
| 63 | + |
| 64 | + Call XMLexporter.rebuildXML(oFileFolderPath, oFileFolderPath & "\src\" & nShortFileName, ErrFlag, ErrMsg, nwb) |
| 65 | + |
| 66 | + If ErrFlag = True Then |
| 67 | + MsgBox (ErrMsg) |
| 68 | + Exit Sub |
| 69 | + End If |
| 70 | + |
| 71 | + nFileName = nwb.FullName |
| 72 | + nwb.Close |
| 73 | + |
| 74 | + Dim FSO As New Scripting.FileSystemObject |
| 75 | + Dim nFile As file, oFile As file |
| 76 | + Set oFile = FSO.GetFile(oFileName) |
| 77 | + Set nFile = FSO.GetFile(nFileName) |
| 78 | + |
| 79 | + oFile.Delete |
| 80 | + nFile.name = nShortFileName |
| 81 | + |
| 82 | + Set nwb = Workbooks.Open(oFileName) |
| 83 | + |
| 84 | + Call Build.importVbaCode(nwb.VBProject) |
| 85 | + MsgBox "Successfully imported VB code and XML content." |
| 86 | + |
| 87 | +End Sub |
0 commit comments