Copy update module from Personal.xlsb workbook to activeworkbook.

huangapple go评论67阅读模式
英文:

Copy update module from Personal.xlsb workbook to activeworkbook

问题

I have a module in personal.xlsb workbook that has 15+ sub procedures with 20,000+ lines of code to upgrade my quoting spreadsheet to the latest version of changes. When it is done running I need to copy over existing modules or delete modules and import the updated modules for the updates to run correctly. Any help is appreciated.

I have searched for answers but have not got anything to run.

英文:

I have a module in personal.xlsb workbook that has 15+ sub procedures with 20,000+ lines of code to upgrade my quoting spreadsheet to the latest version of changes.
when it is done running I need to copy over existing modules or delete modules and import the updated modules for the updates to run correctly.
any help is appreciated.

i have searched for answers but have not got anything to run.

答案1

得分: 1

I have translated the provided text into English. Please note that some parts of the text contain code or technical information that may not translate perfectly:

Good morning,
You can take inspiration from the code of the attached procedures, which are part of a module I created for an application. The object of the procedures of this module is precisely the manipulation of the modules (deletion, import, etc.). The procedures are part of an XLAM or XLSM workbook and run for the ActiveWorkbook.
There is a lot of code, but you will probably find your happiness there.
PS. The comments are in French.
Good luck
Sub import_all_modules_from_backup()
'Imports and replaces modules from the backup folder
ActiveWorkbook.Activate
' * Call search and activate if not already installed
If Not ReferenceActive("C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB", ThisWorkbook) Then
ActiveWorkbook.VBProject.References.AddFromFile "C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"
End If
'Determine the "File Name" variable used in calculating module file paths
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, ".")), "_", "")
'Redefine Source for cycle workbook, ExamProcedure, or Analysis_Sales or purchases
If InStr(source, "Cycles01") > 0 Then
source = "Cycles01"
ElseIf InStr(source, "Cycle") > 0 Then
source = "Cycle_B01"
ElseIf InStr(source, "ExamenP") > 0 Then
source = "Examen_Procedures_01"
ElseIf InStr(source, "AnalysedesVentes0") > 0 Then
source = "Analyse_des_Ventes_01"
ElseIf InStr(source, "AnalysedesTVAREC0") > 0 Then
source = "Analyse_des_TVA_REC_01"
Else
'Remove spaces for VBA module names
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, ".")), " ", "")
End If
'Test if the VBA source folder exists
' * Path to import modules, user's desktop + the constant range("Path_VBA").Value + "BAS_New\" + file name without extension + CLs folder
With ActiveWorkbook
repert = Range("Path_VBA").Value & "BAS_New\" & source & "\"
End With
' * Check if it exists
' * Create a backup folder if it doesn't exist
If Not Dir(repert, vbDirectory) <> vbNullString And Not Dir(repert & "Sauve\*.bas") <> vbNullString Then
MsgBox "Update is impossible, VBA module path does not exist", vbExclamation
GoTo exit_
End If
delete_all_modules 'Delete all modules in the workbook
Import_Module_from_save 'Import type 1 bas modules
Import_Cls_Wb_sh_from_cls 'Import type 1 bas modules
Import_Frm_from_frm
Ren_Mod_End_1 'Rename imported modules that are duplicates
exit_:
End Sub
Sub Update_Development_Modules()
'Imports modules from the development folder
ActiveWorkbook.Activate
' * Call search and activate if not already installed
If Not ReferenceActive("C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB", ThisWorkbook) Then
ActiveWorkbook.VBProject.References.AddFromFile "C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB"
End If
Update_Module_From_New
Update_frm_from_new
End Sub
Sub Import_Module_from_save(Optional shdw As Boolean)
Dim VBProj As VBIDE.VBProject
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, ".")), "_", "")
'Redefine Source for cycle workbook, ExamProcedure, or Analysis_Sales or purchases
If InStr(source, "Cycles01") > 0 Then
source = "Cycles01"
ElseIf InStr(source, "Cycle") > 0 Then
source = "Cycle_B01"
ElseIf InStr(source, "ExamenP") > 0 Then
source = "Examen_Procedures_01"
ElseIf InStr(source, "AnalysedesVentes0") > 0 Then
source = "Analyse_des_Ventes_01"
ElseIf InStr(source, "AnalysedesTVAREC0") > 0 Then
source = "Analyse_des_TVA_REC_01"
Else
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, ".")), " ", "")
End If
Set VBProj = ActiveWorkbook.VBProject
' * Determine the "File Name" variable used in calculating module file paths
source = Replace(Left(Active
<details>
<summary>英文:</summary>
Good morning,
You can take inspiration from the code of the attached procedures, which are part of a module I created for an application. The object of the procedures of this module is precisely the manipulation of the modules (deletion, import, etc.). the procedures are part of an XLAM or XLSM workbook, and run for the Activeworkbook.
There is a lot of code, but you will probably find your happiness there.
There is a lot of code, but you will probably find your happiness there.
PS. The comments are in French.
Good luck
Sub importe_tout_modules_depuis_sauve()
&#39;importe et remplace les modules depuis le dossier de sauvegarde
ActiveWorkbook.Activate
&#39;*Appel recherche et active si non, si non install
If Not ReferenceActive(&quot;C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB&quot;, ThisWorkbook) Then
ActiveWorkbook.VBProject.References.AddFromFile &quot;C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB&quot;
End If
&#39;*determine la variable &quot;Nom de fichier&quot; utilis&#233;e dans le calcul du chemin des fichiers modules
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, &quot;.&quot;) - 1), &quot;_&quot;, &quot;&quot;)
&#39;redefinit Source si classeur de cycle, ou ExamProcedure, ou Analyse_Ventes ou achats
If InStr(1, source, &quot;Cycles01&quot;) &gt; 0 Then
source = &quot;Cycles01&quot;
ElseIf InStr(1, source, &quot;Cycle&quot;) &gt; 0 Then
source = &quot;Cycle_B01&quot;
ElseIf InStr(1, source, &quot;ExamenP&quot;) &gt; 0 Then
source = &quot;Examen_Procedures_01&quot;
ElseIf InStr(1, source, &quot;AnalysedesVentes0&quot;) &gt; 0 Then
source = &quot;Analyse_des_Ventes_01&quot;
ElseIf InStr(1, source, &quot;AnalysedesTVAREC0&quot;) &gt; 0 Then
source = &quot;Analyse_des_TVA_REC_01&quot;
Else
&#39;supprime les espaces pour le nom des modules VBA
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, &quot;.&quot;) - 1), &quot; &quot;, &quot;&quot;)
End If
&#39;test si le dossier des sources vba existe
&#39;*le chemin des modules &#224; importer, bureau de l&#39;utilisateur + la constante range(&quot;Path_VBA&quot;).Value &amp; &quot;BAS_New\&quot; + le nom de ce fichier sans l&#39;extension + dossier CLs
With ActiveWorkbook
repert = Range(&quot;Path_VBA&quot;).Value &amp; &quot;BAS_New\&quot; &amp; source &amp; &quot;\&quot;
End With
&#39;*et v&#233;rifie qu&#39;il existe
&#39;*et cr&#233;e un dossier de sauvegarde si il n&#39;existe pas
&#39;*et v&#233;rifie qu&#39;il existe
&#39;*et cr&#233;e un dossier de sauvegarde si il n&#39;existe pas
If Not Dir(repert, vbDirectory) &lt;&gt; vbNullString And Not Dir(repert &amp; &quot;Sauve\*.bas&quot;) &lt;&gt; vbNullString Then
MsgBox &quot;la mise &#224; jour est impossible, le chemin des modules vba est inexistant&quot;, vbExclamation
GoTo exit_
End If
supprime_tous_les_modules                         &#39;supprime tous les modules du classeur
Import_Module_depuis_save                         &#39;importe les modules e type 1  bas
Import_Cls_Wb_sh_depuis_cls                       &#39;importe les modules e type 1  bas
Import_Frm_depuis_frm
Ren_Mod_End_1                                     &#39;renomme les modules import&#233;s en doublon
&#39;renomme_modules1
exit_:
End Sub
Sub Maj_Modules_Developpement_ext()               &#39;Optional shdw As Boolean)
&#39;importe les modules depuis le dossier de d&#233;veloppement
ActiveWorkbook.Activate
&#39;*Appel recherche et active si non, si non install
If Not ReferenceActive(&quot;C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB&quot;, ThisWorkbook) Then
ActiveWorkbook.VBProject.References.AddFromFile &quot;C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB&quot;
End If
Maj_Module_From_New
Maj_frm_from_new
&#39;renomme_modules1
End Sub
Sub Import_Module_depuis_save(Optional shdw As Boolean)
Dim VBProj As VBIDE.VBProject
&#39;        Dim VBComp As VBIDE.VBComponent
&#39;        Dim CodeMod As VBIDE.CodeModule
Dim StartLine As Long
Dim NumLines As Long
&#39;Dim ProcName As String
Dim repert As String
Dim Module As Variant
Dim nom_module As String
Dim fichier As String
Dim module_import As Variant
&#39;*definition au niveau proc&#233;dure des variable de type optionnal supprim&#233;es en tant que param&#232;tre
&#39;Dim nom_projet As String
Set VBProj = ActiveWorkbook.VBProject
&#39;*determine la variable &quot;Nom de fichier&quot; utilis&#233;e dans le calcul du chemin des fichiers modules
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, &quot;.&quot;) - 1), &quot;_&quot;, &quot;&quot;)
&#39;redefinit Source si classeur de cycle, ou ExamProcedure, ou Analyse_Ventes ou achats
If InStr(1, source, &quot;Cycles01&quot;) &gt; 0 Then
source = &quot;Cycles01&quot;
ElseIf InStr(1, source, &quot;Cycle&quot;) &gt; 0 Then
source = &quot;Cycle_B01&quot;
ElseIf InStr(1, source, &quot;ExamenP&quot;) &gt; 0 Then
source = &quot;Examen_Procedures_01&quot;
ElseIf InStr(1, source, &quot;AnalysedesVentes0&quot;) &gt; 0 Then
source = &quot;Analyse_des_Ventes_01&quot;
ElseIf InStr(1, source, &quot;AnalysedesTVAREC0&quot;) &gt; 0 Then
source = &quot;Analyse_des_TVA_REC_01&quot;
Else
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, &quot;.&quot;) - 1), &quot; &quot;, &quot;&quot;)
End If
&#39;*D&#233;finit le classeur de destination (qui doit &#234;tre pr&#233;alablement ouvert).
Set wb = ActiveWorkbook
&#39;    &#39;*Nomme le projet du classeur actuel au soit fecxtools + nom du fichier sans l&#39;extension  ex: Fecxtools_Cycle_X
&#39;*le chemin des modules &#224; importer, bureau de l&#39;utilisateur + la constante range(&quot;Path_VBA&quot;).Value &amp; &quot;BAS_New\&quot; + le nom de ce fichier sans l&#39;extension + dossier CLs
repert = Range(&quot;Path_VBA&quot;).Value &amp; &quot;BAS_New\&quot; &amp; source &amp; &quot;\&quot;
&#39;*et v&#233;rifie qu&#39;il existe
&#39;*et cr&#233;e un dossier de sauvegarde si il n&#39;existe pas
&#39;*et v&#233;rifie qu&#39;il existe
&#39;*et cr&#233;e un dossier de sauvegarde si il n&#39;existe pas
If Not Dir(repert, vbDirectory) &lt;&gt; vbNullString Then
MsgBox &quot;le dossier n&#39;existe pas&quot;, vbExclamation
GoTo exit_
End If
&#39;*nb_module = Application.VBE.VBProjects(nom_projet).VBComponents.Count
fichier = Dir(repert &amp; &quot;Sauve\*.bas&quot;)
While fichier &lt;&gt; &quot;&quot;
Debug.Print fichier
nom_module = (Left(fichier, InStrRev(fichier, &quot;.&quot;) - 1))
&#39;If Not (UCase(nom_module) = UCase(ControleProcedureActiveDEV)) Then
&#39;importe tous les modules pr&#233;sents
If VerifierExistenceModule(nom_module) = True Then
If ActiveWorkbook.VBProject.VBComponents(nom_module).Type = 1 Then
Set Module = ActiveWorkbook.VBProject.VBComponents(nom_module)
ActiveWorkbook.VBProject.VBComponents.Remove (Module)
Set module_import = ActiveWorkbook.VBProject.VBComponents.Import(repert &amp; &quot;Sauve\&quot; &amp; fichier)
&#39;Debug.Print fichier
End If
Else                                              &#39;&#39;If propose = True Then                &#39; en pause
&#39;If MsgBox(&quot;voulez-vous importer ce nouveau module &quot; &amp; Chr(13) &amp; nom_module, vbYesNo) = 6 Then
Set module_import = ActiveWorkbook.VBProject.VBComponents.Import(repert &amp; &quot;Sauve\&quot; &amp; fichier)
Debug.Print fichier
&#39;End If
&#39;End If
End If
fichier = Dir
Wend
exit_:
End Sub
Sub Maj_Module_From_New()
&#39;recupere et remplace les modules depuis
&#39;C:\Users\phm\Desktop\DEV\BAS_New\A_New_Communs
Dim VBProj As VBIDE.VBProject
&#39;        Dim VBComp As VBIDE.VBComponent
&#39;        Dim CodeMod As VBIDE.CodeModule
Dim StartLine As Long
Dim NumLines As Long
&#39;Dim ProcName As String
Dim repert As String
Dim Module As Variant
Dim nom_module As String
Dim fichier As String
Dim module_import As Variant
&#39;*definition au niveau proc&#233;dure des variable de type optionnal supprim&#233;es en tant que param&#232;tre
&#39;Dim nom_projet As String
Dim propose As Boolean
Set VBProj = ActiveWorkbook.VBProject
repert = Range(&quot;Path_VBA&quot;).Value &amp; &quot;BAS_New\A_New_Communs\&quot; &#39;&amp; &quot;New\&quot;
&#39;*et v&#233;rifie qu&#39;il existe
&#39;*et cr&#233;e un dossier de sauvegarde si il n&#39;existe pas
If Not Dir(repert, vbDirectory) &lt;&gt; vbNullString Then
MsgBox &quot;le dossier n&#39;existe pas ou est vide&quot;, vbExclamation
GoTo exit_
End If
&#39;*demande si on doit proposer d&#39;installer les nouveaux modules
If MsgBox(&quot;proposition de nx modules&quot;, vbYesNo) = 6 Then propose = True
&#39;*nb_module = Application.VBE.VBProjects(nom_projet).VBComponents.Count
fichier = Dir(repert &amp; &quot;\*.bas&quot;)
While fichier &lt;&gt; &quot;&quot;
nom_module = (Left(fichier, InStrRev(fichier, &quot;.&quot;) - 1))
&#39;Debug.Print nom_module
&#39;If Left(nom_module, 5) = &quot;A_Exp&quot; Then Stop
&#39;If Not (UCase(nom_module) = UCase(ControleProcedureActiveDEV)) Then
If VerifierExistenceModule(nom_module) = True Then
If ActiveWorkbook.VBProject.VBComponents(nom_module).Type = 1 Then
&#39;If Left(Fichier, 1) = &quot;X&quot; Then Stop
Debug.Print fichier
Set Module = ActiveWorkbook.VBProject.VBComponents(nom_module)
ActiveWorkbook.VBProject.VBComponents.Remove (Module)
Set module_import = ActiveWorkbook.VBProject.VBComponents.Import(repert &amp; fichier)
End If
ElseIf propose = True Then                        &#39; en pause
If MsgBox(&quot;voulez-vous importer ce nouveau module &quot; &amp; Chr(13) &amp; nom_module, vbYesNo) = 6 Then
Set module_import = ActiveWorkbook.VBProject.VBComponents.Import(repert &amp; &quot;\&quot; &amp; fichier)
Debug.Print fichier
End If
End If
&#39;End If
&#39;End If
&#39;        &#39;pour une procedure sp&#233;cifique dans le module
&#39;        ProcName = &quot;NomProcedure&quot;
&#39;
&#39;        With CodeMod
&#39;            &#39;VBProj.VBComponents(&quot;Module2&quot;)&#39;
&#39;            &#39;.ProcName.Delete
&#39;            StartLine = .ProcStartLine(ProcName, vbext_pk_Proc)
&#39;            NumLines = .ProcCountLines(ProcName, vbext_pk_Proc)
&#39;            .DeleteLines StartLine:=StartLine, Count:=NumLines
&#39;        End With
fichier = Dir
Wend
exit_:
End Sub
&#39;*************************************************************************************&#39;
&#39;*Importe le code des feuilles et workbook
&#39;*
&#39;*
&#39;*
&#39;*
&#39;*************************************************************************************&#39;
Sub Import_Cls_Wb_sh_depuis_cls(Optional shdw As Boolean)
&#39;* importe les fichier BAS correspondant aux macors de feuilles ou workbook, depuis
&#39;* le dossier
&#39;* C:\Users\phm\Desktop\DEV\BAS_New\PMSYNTHESE\Cls
&#39;*N&#233;cessite d&#39;activer la r&#233;f&#233;rence &quot;Microsoft Visual Basic for Applications Extensibility 5.3&quot;
Dim wb     As Workbook
Dim oModule As CodeModule
Dim VBComp As VBComponent
Dim x      As Integer
Dim cible  As String
Dim source As String
Dim repert As String
Dim nom_projet As Variant
Dim nom_module As String
Dim fichier As String
&#39;*determine la variable utilis&#233;e dans le calcul du chemin des fichiers modules
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, &quot;.&quot;) - 1), &quot;_&quot;, &quot;&quot;)
&#39;redefinit Source si classeur de cycle
&#39;redefinit Source si classeur de cycle, ou ExamProcedure, ou Analyse_Ventes ou achats
If InStr(1, source, &quot;Cycles01&quot;) &gt; 0 Then
source = &quot;Cycles01&quot;
ElseIf InStr(1, source, &quot;Cycle&quot;) &gt; 0 Then
source = &quot;Cycle_B01&quot;
ElseIf InStr(1, source, &quot;ExamenP&quot;) &gt; 0 Then
source = &quot;Examen_Procedures_01&quot;
ElseIf InStr(1, source, &quot;AnalysedesVentes0&quot;) &gt; 0 Then
source = &quot;Analyse_des_Ventes_01&quot;
ElseIf InStr(1, source, &quot;AnalysedesTVAREC0&quot;) &gt; 0 Then
source = &quot;Analyse_des_TVA_REC_01&quot;
Else
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, &quot;.&quot;) - 1), &quot; &quot;, &quot;&quot;)
End If
&#39;*D&#233;finit le classeur de destination (qui doit &#234;tre pr&#233;alablement ouvert).
Set wb = ActiveWorkbook                           &#39;Workbooks(&quot;CibleThisWB.xlsx&quot;)
&#39;    &#39;*Nomme le projet du classeur actuel au soit fecxtools + nom du fichier sans l&#39;extension  ex: Fecxtools_Cycle_X
&#39;    Application.VBE.ActiveVBProject.Name = &quot;fecxtools_&quot; &amp; Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, &quot;.&quot;) - 1), &quot; &quot;, &quot;&quot;)
&#39;    nom_projet = Application.VBE.ActiveVBProject.Name
&#39;*le chemin des modules &#224; importer, bureau de l&#39;utilisateur + la constante range(&quot;Path_VBA&quot;) &amp; &quot;BAS_New\&quot; + le nom de ce fichier sans l&#39;extension + dossier CLs
repert = Range(&quot;Path_VBA&quot;).Value &amp; &quot;BAS_New\&quot; &amp; source &amp; &quot;\&quot; &#39;&amp; &quot;\New&quot;
&#39;*et v&#233;rifie qu&#39;il existe
&#39;*et cr&#233;e un dossier de sauvegarde si il n&#39;existe pas
If Not Dir(repert, vbDirectory) &lt;&gt; vbNullString Then
MsgBox &quot;le dossier n&#39;existe pas&quot;, vbExclamation
GoTo exit_
End If
&#39;*nb_module = Application.VBE.VBProjects(nom_projet).VBComponents.Count
fichier = Dir(repert &amp; &quot;CLS\*.cls&quot;)
While fichier &lt;&gt; &quot;&quot;
&#39;*Set wb = Workbooks.Open(Fichier)
nom_module = (Left(fichier, InStrRev(fichier, &quot;.&quot;) - 1))
&#39;If Not (UCase(nom_module) = UCase(ControleProcedureActiveDEV)) Then
If VerifierExistenceModule(nom_module) = True Then
If ActiveWorkbook.VBProject.VBComponents(nom_module).Type = 100 Then
&#39;*d&#233;fini le module &#224; importer, et l&#39;importe (en tant que module de classe)
Set VBComp = wb.VBProject.VBComponents.Import(repert &amp; &quot;CLS\&quot; &amp; fichier)
&#39;*Le renomme (pour le supprimer plus facilement ult&#233;rieurement, il va aller dans modules de classe
cible = &quot;Temp&quot;
VBComp.Name = cible
Set oModule = VBComp.CodeModule
&#39;*Transf&#232;re les donn&#233;es charg&#233;es dans le module de classe activeworkbook.
&#39;*Attention les donn&#233;es existantes dans &quot;activeworkbook&quot; sont &#233;cras&#233;es.
With wb.VBProject.VBComponents(nom_module).CodeModule
x = .CountOfLines
.DeleteLines 1, x
.InsertLines 1, oModule.Lines(1, oModule.CountOfLines)
End With
&#39;*Suppression du module ancien
With wb.VBProject.VBComponents
.Remove .Item(cible)
End With
Debug.Print fichier
Else
MsgBox &quot;le module sheet ou activeworkbook &quot; &amp; Chr(13) &amp; nom_module &amp; Chr(13) &amp; &quot; ne peut &#234;tre import&#233;, si il n&#39;existe pas au pr&#233;alable&quot;, vbExclamation
&#39;*ActiveWorkbook.VBProject.VBComponents(&quot;activeworkbook&quot;).CodeModule.AddFromFile (repert &amp; &quot;\&quot; &amp; fichier)
&#39;*pour renommer un nodule CLS ****** activeworkbook_.[_CodeName] = &quot;activeworkbook&quot;
End If
End If
&#39;End If
&#39;*passe au fichier suivant
fichier = Dir
Wend
exit_:
End Sub
Sub Import_Frm_depuis_frm(Optional shdw As Boolean)
&#39;*N&#233;cessite d&#39;activer la r&#233;f&#233;rence &quot;Microsoft Visual Basic for Applications Extensibility 5.3&quot;
&#39;* importe les fichier BAS correspondant aux macors de feuilles ou workbook, depuis
&#39;* le dossier
&#39;* C:\Users\phm\Desktop\DEV\BAS_New\PMSYNTHESE\FRM
Dim wb     As Workbook
Dim VBComp As VBComponent
Dim cible  As String
Dim source As String
Dim repert As String
Dim nom_projet As Variant
Dim nom_module As String
Dim fichier As String
Dim propose As Boolean
&#39;*determine la variable utilis&#233;e dans le calcul du chemin des fichiers modules
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, &quot;.&quot;) - 1), &quot;_&quot;, &quot;&quot;)
&#39;redefinit Source si classeur de cycle
&#39;redefinit Source si classeur de cycle, ou ExamProcedure, ou Analyse_Ventes ou achats
If InStr(1, source, &quot;Cycles01&quot;) &gt; 0 Then
source = &quot;Cycles01&quot;
ElseIf InStr(1, source, &quot;Cycle&quot;) &gt; 0 Then
source = &quot;Cycle_B01&quot;
ElseIf InStr(1, source, &quot;ExamenP&quot;) &gt; 0 Then
source = &quot;Examen_Procedures_01&quot;
ElseIf InStr(1, source, &quot;AnalysedesVentes0&quot;) &gt; 0 Then
source = &quot;Analyse_des_Ventes_01&quot;
ElseIf InStr(1, source, &quot;AnalysedesTVAREC0&quot;) &gt; 0 Then
source = &quot;Analyse_des_TVA_REC_01&quot;
Else
source = Replace(Left(ActiveWorkbook.Name, InStrRev(ActiveWorkbook.Name, &quot;.&quot;) - 1), &quot; &quot;, &quot;&quot;)
End If
&#39;*D&#233;finit le classeur de destination (qui doit &#234;tre pr&#233;alablement ouvert).
Set wb = ActiveWorkbook                           &#39;Workbooks(&quot;CibleThisWB.xlsx&quot;)
&#39;*le chemin des modules &#224; importer, bureau de l&#39;utilisateur + la constante range(&quot;Path_VBA&quot;) &amp; &quot;BAS_New\&quot; + le nom de ce fichier sans l&#39;extension + dossier Frm
repert = Range(&quot;Path_VBA&quot;).Value &amp; &quot;BAS_New\&quot; &amp; source &amp; &quot;\&quot; &#39;&amp; &quot;New\&quot;
&#39;*demande si on doit proposer d&#39;installer les nouveaux modules USERFORM
If Not Dir(repert, vbDirectory) &lt;&gt; vbNullString Then
MsgBox &quot;le dossier n&#39;existe pas&quot;, vbExclamation
GoTo exit_
End If
&#39;If MsgBox(&quot;proposition de nx modules USEERFORM&quot;, vbYesNo) = 6 Then propose = True
&#39;*Nomme le projet du classeur actuel au soit fecxtools + nom du fichier sans l&#39;extension  ex: Fecxtools_Cycle_X
&#39;*compte le nombre de modules
&#39;*nb_module = Application.VBE.VBProjects(nom_projet).VBComponents.Count
fichier = Dir(repert &amp; &quot;Frm\*.frm&quot;)
While fichier &lt;&gt; &quot;&quot;
&#39;*Set wb = Workbooks.Open(Fichier)
Debug.Print fichier
nom_module = (Left(fichier, InStrRev(fichier, &quot;.&quot;) - 1))
If Not (UCase(nom_module) = UCase(ControleProcedureActiveDEV)) Then
&#39;            If VerifierExistenceModule(nom_module) = True Then
&#39;                With wb.VBProject.VBComponents
&#39;                    .Remove .Item(nom_module)
&#39;                End With
Set VBComp = wb.VBProject.VBComponents.Import(repert &amp; &quot;Frm\&quot; &amp; fichier)
&#39;            ElseIf propose = True Then
&#39;                If MsgBox(&quot;voulez-vous importer ce nouveau module &quot; &amp; Chr(13) &amp; nom_module, vbYesNo) = 6 Then
Else
Set VBComp = wb.VBProject.VBComponents.Import(repert &amp; &quot;Frm\&quot; &amp; fichier)
Debug.Print fichier
End If
&#39;End If
&#39;End If
fichier = Dir
Wend
exit_:
End Sub
Sub Maj_frm_from_new(Optional shdw As Boolean)
&#39;*N&#233;cessite d&#39;activer la r&#233;f&#233;rence &quot;Microsoft Visual Basic for Applications Extensibility 5.3&quot;
&#39;* importe les fichier BAS correspondant aux macors de feuilles ou workbook, depuis
&#39;* le dossier
&#39;* C:\Users\phm\Desktop\DEV\BAS_New\PMSYNTHESE\FRM
Dim wb     As Workbook
Dim VBComp As VBComponent
Dim cible  As String
Dim source As String
Dim repert As String
Dim nom_projet As Variant
Dim nom_module As String
Dim fichier As String
Dim propose As Boolean
&#39;*D&#233;finit le classeur de destination (qui doit &#234;tre pr&#233;alablement ouvert).
Set wb = ActiveWorkbook                           &#39;Workbooks(&quot;CibleThisWB.xlsx&quot;)
&#39;*le chemin des modules &#224; importer, bureau de l&#39;utilisateur + la constante range(&quot;Path_VBA&quot;).Value &amp; &quot;BAS_New\&quot; + le nom de ce fichier sans l&#39;extension + dossier Frm
repert = Range(&quot;Path_VBA&quot;).Value &amp; &quot;BAS_New\A_New_Communs\&quot; &#39;&amp; &quot;New\&quot;
&#39;*et v&#233;rifie qu&#39;il existe
&#39;*et cr&#233;e un dossier de sauvegarde si il n&#39;existe pas
If Not Dir(repert, vbDirectory) &lt;&gt; vbNullString Then
MsgBox &quot;le dossier n&#39;existe pas ou est vide&quot;, vbExclamation
GoTo exit_
End If
&#39;If MsgBox(&quot;proposition de nx modules USEERFORM&quot;, vbYesNo) = 6 Then propose = True
&#39;*Nomme le projet du classeur actuel au soit fecxtools + nom du fichier sans l&#39;extension  ex: Fecxtools_Cycle_X
&#39;*compte le nombre de modules
&#39;*nb_module = Application.VBE.VBProjects(nom_projet).VBComponents.Count
fichier = Dir(repert &amp; &quot;\*.frm&quot;)
While fichier &lt;&gt; &quot;&quot;
&#39;*Set wb = Workbooks.Open(Fichier)
Debug.Print fichier
nom_module = (Left(fichier, InStrRev(fichier, &quot;.&quot;) - 1))
If Not (UCase(nom_module) = UCase(ControleProcedureActiveDEV)) Then
If VerifierExistenceModule(nom_module) = True Then
With wb.VBProject.VBComponents
.Remove .Item(nom_module)
End With
Set VBComp = wb.VBProject.VBComponents.Import(repert &amp; fichier)
ElseIf propose = True Then
If MsgBox(&quot;voulez-vous importer ce nouveau module &quot; &amp; Chr(13) &amp; nom_module, vbYesNo) = 6 Then
If Left(fichier, 1) &lt;&gt; x Then
Set VBComp = wb.VBProject.VBComponents.Import(repert &amp; fichier)
Debug.Print fichier
End If
End If
End If
End If
fichier = Dir
Wend
exit_:
End Sub
Sub renomme_modules1()
Dim nb_module As Integer
Dim nom_projet As String
Dim i      As Integer
Dim wb     As Workbook
Dim VBProj As VBIDE.VBProject
Dim New_name_Module As String
Set wb = ActiveWorkbook
Set VBProj = ActiveWorkbook.VBProject
&#39;*Nomme le projet du classeur actuel au soit fecxtools + nom du fichier sans l&#39;extension  ex: Fecxtools_Cycle_X
&#39;Application.VBE.ActiveVBProject.Name = &quot;fecxtools_&quot; &amp; Replace(Left(ThisWorkbook.Name, InStrRev(ThisWorkbook.Name, &quot;.&quot;) - 1), &quot; &quot;, &quot;&quot;)
nb_module = VBProj.VBComponents.Count
&#39;nom_projet = Application.VBE.ActiveVBProject.Name
&#39;nb_module = ActiveWorkbook.VBE.VBProjects(nom_projet).VBComponents.Count
For i = nb_module To 1 Step -1
&#39;*si le module est un module  standard (type 1)
Debug.Print VBProj.VBComponents(i).Name
If VBProj.VBComponents(i).Type = 1 Then
If Right(VBProj.VBComponents(i).Name, 1) = &quot;1&quot; Then
VBProj.VBComponents.Remove VBProj.VBComponents(Left(VBProj.VBComponents(i).Name, Len(VBProj.VBComponents(i).Name) - 1))
&#39;*supprime le dernier 1
&#39;New_name_Module = Left(VBProj.VBComponents(i).Name, _
&#39;Len(VBProj.VBComponents(i).Name) - 1)
&#39;VBProj.VBComponents(i).Name = New_name_Module
End If
End If
Next
End Sub
Sub Ren_Mod_End_1()
Dim VBComp As Object
Dim VBComps As Object
Set VBComps = ActiveWorkbook.VBProject.VBComponents
For Each VBComp In VBComps
&#39;MsgBox VBComp.Name &amp; &quot;=&quot; &amp; CompTypeToName(VBComp) &amp; &quot; = &quot; &amp; VBComp.Type
If VBComp.Type = 1 Then
If Right(VBComp.Name, 1) = &quot;1&quot; Then
&#39;passe les composants feuille, dont le code name peut &#234;tre termin&#233; par 1
If VBComp.Type &lt;&gt; 100 Then
VBComp.Name = Left(VBComp.Name, Len(VBComp.Name) - 1)
End If
End If
End If
Next VBComp
End Sub
Sub supprime_tous_les_modules()
Dim VBComp As Object
Dim VBComps As Object
Set VBComps = ActiveWorkbook.VBProject.VBComponents
For Each VBComp In VBComps
Select Case VBComp.Type
Case 100
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
Case Else
VBComps.Remove VBComp
End Select
Next VBComp
exit_:
End Sub
&#39;==============================================================
Sub ListModules()
Dim VBComp As VBComponent
Dim Msg As String
For Each VBComp In ActiveWorkbook.VBProject.VBComponents
Msg = Msg &amp; VBComp.Name &amp; &quot; Type: &quot; &amp; CompTypeToName(VBComp) &amp; Chr(13)
Next VBComp
MsgBox Msg
End Sub
Function CompTypeToName(VBComp As VBComponent) As String
Select Case VBComp.Type
Case vbext_ct_ActiveXDesigner
CompTypeToName = &quot;ActiveX Designer&quot;
Case vbext_ct_ClassModule
CompTypeToName = &quot;Class Module&quot;
Case vbext_ct_Document
CompTypeToName = &quot;Document&quot;
Case vbext_ct_MSForm
CompTypeToName = &quot;MS Form&quot;
Case vbext_ct_StdModule
CompTypeToName = &quot;Standard Module&quot;
Case Else
End Select
End Function
</details>

huangapple
  • 本文由 发表于 2023年5月14日 02:52:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76244399.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定