Utiliser la macro pour créer un lien vers une fiche créée

beowulf97

XLDnaute Nouveau
Bonjour à tous,

voilà je vais vous expliquer mon problème actuel :

J'ai un fichier me permettant de créer des "fiches clients", j'entre le nom, je sélectionne ensuite un paramètre dans une liste déroulante et ensuite en utilisant le bouton "update", grâce à la macro, je créée la fiche client associée (du même nom).

Ce que je souhaiterai faire :
Je souhaiterai, en plus de créer la fiche client ( ce que j'ai réussi, à faire ), rendre le nom du client de ma première page cliquable (en faire un lien vers la page client créée au lieu de le laisser en tant que seul nom ).

Voici le code de la macro que j'utilise :

Code:
Sub Macro()
'
' Macro Update File
'
    Dim n As Integer, nI As Integer, m As Integer, Rep As Integer, Lang As Integer
    Dim IType As String, WName As String, MName As String, IName As String, Prompt1(1 To 2) As String, _
        Title(1 To 2) As String, WPrompt(1 To 2) As String, WTitle(1 To 2) As String
    Dim IPre As Variant
    Dim Control As Boolean
'
    WPrompt(1) = "Ouvrez d'abord le fichier 'Master Commissioning sheets.xls' SVP."
    WPrompt(2) = "Please open first the 'Master Commissioning sheets.xls' file."
    Prompt1(1) = "Etes-vous sûre de vouloir effacer la fiche de MES supprimée ?"
    Prompt1(2) = "Are you sure you want to delete the removed commissioning sheet ?"
    WTitle(1) = "Ouverture Master"
    WTitle(2) = "Master Opening"
    Title(1) = "Suuprimer une fiche de mise en service"
    Title(2) = "Delete commissioning sheet"
    MName = "Master Commissioning sheets.xls"
    Control = True
    n = 0
    nI = 0
    NNspec = 0
'
    WName = ActiveWorkbook.Name
    If (Workbooks(WName).Worksheets(1).Cells(1, 16).Value = "FR") Then
        Lang = 1
    Else
        Lang = 2
    End If
'
    For n = 1 To Workbooks.Count
        If (Workbooks(n).Name = MName) Then
            Exit For
        End If
    Next
    If (n > Workbooks.Count) Then
        Rep = MsgBox(WPrompt(Lang), vbOKOnly, WTitle(Lang))
    Else
        Application.ScreenUpdating = False
        Workbooks(WName).Activate
        Worksheets("Instruments & Equipments List").Activate
        Do While Control
            nI = nI + 1
            If (Trim(Workbooks(WName).Worksheets(1).Cells(8 + nI, 1).Value) = "") Then
                Control = False
            End If
        Loop
        nI = nI - 1
'
        For n = 1 To nI
            IType = Workbooks(WName).Worksheets(1).Cells(8 + n, 14).Value
            If (Workbooks(WName).Worksheets(1).Cells(7 + n, 14).Value = "?") Then
                If (n = 1) Then
                    IPre = 1
                Else
                    For m = (7 + n) To 8 Step -1
                        If (Workbooks(WName).Worksheets(1).Cells(m, 14).Value <> "?") Then
                            IPre = Workbooks(WName).Worksheets(1).Cells(m, 1).Value
                            Exit For
                        End If
                    Next
                    If (m < 8) Then
                        IPre = 1
                    End If
                End If
            Else
                IPre = Workbooks(WName).Worksheets(1).Cells(7 + n, 1).Value
            End If
            IName = Workbooks(WName).Worksheets(1).Cells(8 + n, 1).Value
            For m = 2 To Workbooks(WName).Worksheets.Count
                If (IName = Workbooks(WName).Worksheets(m).Name) Then
                    Exit For
                End If
            Next
            If (m > Workbooks(WName).Worksheets.Count) Then
                For m = 1 To Workbooks(MName).Worksheets.Count
                    If (Workbooks(MName).Worksheets(m).Name = IType) Then
                        Exit For
                    End If
                Next
                If (m <= Workbooks(MName).Worksheets.Count) Then
                    Windows(MName).Activate
                    Sheets(IType).Select
                    If (n = 1) Then
                        Sheets(IType).Copy After:=Workbooks(WName).Sheets(1)
                    Else
                        Sheets(IType).Copy After:=Workbooks(WName).Sheets(IPre)
                    End If
                    Windows(WName).Activate
                    ActiveSheet.Name = IName
                    Cells(6, 3).Formula = "='" & Worksheets(1).Name & "'!$D$2"
                    Cells(7, 3).Formula = "='" & Worksheets(1).Name & "'!$D$3"
                    Cells(8, 3).Formula = "='" & Worksheets(1).Name & "'!$D$4"
                    Cells(12, 3).Formula = "='" & Worksheets(1).Name & "'!$B$" & (8 + n)
                    Cells(12, 8).Formula = "='" & Worksheets(1).Name & "'!$A$" & (8 + n)
                    Cells(12, 12).Formula = "='" & Worksheets(1).Name & "'!$L$" & (8 + n)
                    Cells(13, 3).Formula = "='" & Worksheets(1).Name & "'!$D$" & (8 + n)
                    Sheets(1).Activate
                Else
                    Workbooks(WName).Worksheets(1).Cells(8 + n, 14).Value = "?"
                End If
            Else
                For m = 1 To Workbooks(MName).Worksheets.Count
                    If (Workbooks(MName).Worksheets(m).Name = IType) Then
                        Exit For
                    End If
                Next
                If (m > Workbooks(MName).Worksheets.Count) Then
                    Workbooks(WName).Worksheets(1).Cells(8 + n, 14).Value = "?"
                End If
                If (n = 1) Then
                    Worksheets(IName).Move After:=Worksheets(1)
                Else
                    Worksheets(IName).Move After:=Worksheets(IPre)
                End If
            End If
        Next
'
        Control = False
        For m = 2 To Workbooks(WName).Worksheets.Count
            For n = 1 To nI
                If (Workbooks(WName).Worksheets(1).Cells(8 + n, 1).Value = Workbooks(WName).Worksheets(m).Name) Then
                    Exit For
                End If
            Next
            If (n > nI) Then
                If Not Control Then
                    Rep = MsgBox(Prompt1(Lang), vbYesNo + vbDefaultButton2, Title(Lang))
                    Control = True
                End If
                If (Rep = 6) Then
                    Workbooks(WName).Worksheets(m).Select
                    Application.DisplayAlerts = False
                    ActiveWindow.SelectedSheets.Delete
                    Application.DisplayAlerts = False
                Else
                    Exit For
                End If
            End If
        Next
'
        Application.ScreenUpdating = True
        Workbooks(WName).Worksheets(1).Activate
'
    End If
'
End Sub
'
Sub SelectCode(Row As Integer, Col As Integer)
'
'Macro Select Sheet Code
'
    Dim n As Integer, m As Integer, p As Integer, nCode As Integer, Rep As Integer, Spec As Integer
    Dim CodeTitle() As String, Prompt1 As String, Prompt2 As String, Prompt3 As String, MName As String, _
        Sort(1 To 2) As String
'
    Prompt1 = "Please open first 'Master Commissioning sheets.xls' file"
    Prompt2 = "Select the Instrument/Equipment code"
    Prompt3 = "Code unknown!" & Chr(13) & "Select the Instrument/Equipment code from the list below"
    MName = "Master Commissioning sheets.xls"
'
    For n = 1 To Workbooks.Count
        If (Workbooks(n).Name = MName) Then
            Exit For
        End If
    Next
    If (n > Workbooks.Count) Then
        Rep = MsgBox(Prompt1, vbOKOnly, "Open Master Workbook")
    Else
        nCode = Workbooks(MName).Worksheets.Count
        ReDim CodeTitle(nCode, 2)
        For n = 1 To nCode
            CodeTitle(n, 1) = Workbooks(MName).Worksheets(n).Name
            CodeTitle(n, 2) = Workbooks(MName).Worksheets(n).Cells(11, 1).Value
        Next
'
        For n = 2 To nCode
            For m = 1 To n
                If (CodeTitle(n, 1) < CodeTitle(m, 1)) Then
                    Sort(1) = CodeTitle(n, 1)
                    Sort(2) = CodeTitle(n, 2)
                    For p = n - 1 To m Step -1
                        CodeTitle(p + 1, 1) = CodeTitle(p, 1)
                        CodeTitle(p + 1, 2) = CodeTitle(p, 2)
                    Next
                    CodeTitle(m, 1) = Sort(1)
                    CodeTitle(m, 2) = Sort(2)
                    Exit For
                End If
            Next
        Next
'
'
        With UserForm1
            .Caption = "Code Selection"
            If ((Trim(ActiveSheet.Cells(Row, Col).Value) = "?") Or (Trim(ActiveSheet.Cells(Row, Col).Value) = "")) Then
                .Label1.Caption = Prompt2
            Else
                For n = 1 To nCode
                    If (Trim(ActiveSheet.Cells(Row, Col).Value) = CodeTitle(n, 1)) Then
                        Exit For
                    End If
                Next
                If (n <= nCode) Then
                    Spec = n - 1
                    .Label1.Caption = ""
                Else
                    Spec = 0
                    .Label1.Caption = Prompt3
                End If
            End If
            .ComboBox1.Clear
            For n = 1 To nCode
                .ComboBox1.AddItem CodeTitle(n, 1) & " : " & CodeTitle(n, 2)
            Next
            .ComboBox1.ListIndex = Spec
            .Show
            If (.Tag = "1") Then
                ActiveSheet.Cells(Row, Col).Value = CodeTitle(.ComboBox1.ListIndex + 1, 1)
            End If
        End With
    End If
'
End Sub

Je précise que le nom des clients est affiché dans la colonne "A" à partir de "A9" inclus.

Voilà j'espère que vous pourrez m'aider.

Merci d'avance

PS: J'ai pensé utiliser une formule pour que les noms des clients soient automatiquement des liens, et qu'ensuite avec la macro actuelle, la fiche soit créée et donc que le lien fonctionne..

Ou créer une autre colonne nommée "lien" et donc au lieu de mettre à jour le nom du client pour en faire un lien, Créer directement le lien dans la colonne approppriée..

Mais je ne sais faire aucun des deux :s
 

Discussions similaires

Statistiques des forums

Discussions
315 095
Messages
2 116 165
Membres
112 675
dernier inscrit
Tazra_IMOU