Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a sub from a different work book

In a PERSONAL.XLSB workbook, I have this code:

Public Sub Password(ByVal Target As Range)
    a = ""
    For n = 1 To Len(Target)
        a = a & "*"
    Next n
    Target.NumberFormat = """" & a & """;""" & a & """;""" & a & """;""" & a & """"
End Sub

In my new workbook, I have this code:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = Info.Range("AA9").Address Then
        Workbooks("PERSONAL.XLSB").Password Target
    End If
End Sub

I keep getting an error saying, Compile error: Invalid use of property

like image 622
Makai Avatar asked Jan 12 '23 12:01

Makai


1 Answers

Here's how you run a macro from your personal workbook:

Application.Run "PERSONAL.XLSB!Password", Target

[EDIT] It's worth noting that instead of a loop to build the * string, you could do this:

Public Sub Password(ByVal Target As Range)

    Dim sMask as String

    sMask = Mid(WorksheetFunction.Rept(";""" & String(Len(Target.Value), "*") & """", 4), 2)
    Target.NumberFormat = sMask

End Sub
like image 106
tigeravatar Avatar answered Jan 21 '23 01:01

tigeravatar