Add/Replace code modules in several Visio files

Started by ivan, December 08, 2009, 07:03:12 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ivan

Situation:
i've got the latest file with good working code. there're like 15 modules in it -20-30 macro. does varius stuff editing visio document conyent
there're lots of more old files with outdated code.
i have to edit all the files but using the newest code.
how can i replace all the code in older files with the code from the newest file ? scripted solution needed ((

minduser


Paul Herber

There's no access to this from within Visio, however, one idea has occurred to me ...
Software exists that can automate Windows tasks by recording keyboard and mouse actions and then playing them back. Maybe this route would be worth exploring.

Google for 'windows keyboard and mouse recorder'.

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

Zigoto

Sorry Paul but there is access to this within visio.

you have first to enable "approved access to object model VBA" or something like this . My visio is in French and its a translation.
Find enclosed pictures of the french menu and edit boxes

then you can use the following code in one VSS file


Sub Patch01()

Dim oVsd As Visio.Document

Dim oProject As VBProject
Dim oComponent As VBComponent
Dim oCode As CodeModule

For Each oVsd In Application.Documents
    If UCase(Right(oVsd.Name, 3)) = "VSD" Then
        Set oProject = oVsd.VBProject
        Debug.Print oProject.Name
        '-------------------------------------
        Call Mjn_DeleteCode("function_to_be_changed", oProject) 'this function is in the VSD
        '-------------------------------------
        i = oProject.VBComponents.Count
        Set oCode = oProject.VBComponents(1).CodeModule
        oCode.AddFromFile "path\VisioPatch01.txt" 'in this txt file you put the new code
    End If 'on traite un VSD
Next oVsd
End Sub



The delete function itself


Public Function Mjn_DeleteCode(MacroName As String, Optional oProject As VBProject)

Dim oComponent As VBComponent
Dim oCode As CodeModule
Dim i, j As Integer
Dim ProcName As String

    If oProject Is Nothing Then Set oProject = ThisDocument
    For Each oComponent In oProject.VBComponents
        Set oCode = oComponent.CodeModule
        Debug.Print oCode
   
        If oCode.CountOfLines > 0 Then
            If oCode.Lines(1, oCode.CountOfLines) Like "*Sub " & MacroName & "*" Or oCode.Lines(1, oCode.CountOfLines) Like "*Function " & MacroName & "*" Then  'la macro à supprimer existe dans le code
                i = oCode.CountOfDeclarationLines + 1
                Do Until i >= oCode.CountOfLines
                    ProcName = oCode.ProcOfLine(i, vbext_pk_Proc)
                    Debug.Print ProcName
                    If UCase(ProcName) = UCase(MacroName) Then
                        j = oCode.ProcCountLines(ProcName, vbext_pk_Proc)
                        oCode.DeleteLines i, j
                        Exit Function
                    End If
                    i = i + oCode.ProcCountLines(ProcName, vbext_pk_Proc)
                Loop
            End If
        End If
Next oComponent
End Function



HIH
Ziorg