1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| Attribute VB_Name = "RESERVED_CATIA"
Option Private Module
Option Explicit
Private Const PATH_SCRIPT_SOURCE As String = "..."
'
Public Sub import()
'#############################################################################
'# cleans VBA up before source code imports #################################################
'closes all forms
Dim frm As MSForms.UserForm: For Each frm In VBA.UserForms
Unload Object:=frm 'doesn't seem to work
Set frm = Nothing'doesn't seem to work
Next frm
'##############################################################################
Dim files As New Collection
With New Scripting.FileSystemObject
'loops through all file saved from CATIA
Dim file As Scripting.file: For Each file In .GetFolder(folderPath:=PATH_SCRIPT_SOURCE).files
If file.name Like "RESERVED*" Then GoTo skip_file
With New VBScript_RegExp_55.RegExp
.ignoreCase = True
.pattern = "\.(bas|cls|frm)$"
If .test(sourceString:=file.name) Then files.add item:=file
End With
skip_file:
Next file
End With
With New MSAPC.Apc
With .projects(index:=1).VBProject
'removes all files
Dim component As VBIDE.VBComponent: For Each component In .VBComponents
'skips active module
If Not component.name Like "RESERVED*" Then .VBComponents.remove VBComponent:=component
Next component
'imports files
For Each file In files
'skips active module
If Not file.name Like "RESERVED*" Then .VBComponents.import fileName:=file.path
Next file
'update codes in order to ensure compatibility between CATIA and Excel
For Each component In .VBComponents
'skips code
If component.name Like "RESERVED*" _
Or component.name = "..." Then GoTo skip_component
skip_component:
Next component
End With
End With
Debug.Print "Source files were imported from " & PATH_SCRIPT_SOURCE & ".."
End Sub |
Partager