Consulting

Results 1 to 6 of 6

Thread: Adding line numbers to VBE Code using MZ-Tools

  1. #1
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location

    Adding line numbers to VBE Code using MZ-Tools

    Hi Folks

    I'm using the MZ-Tools 8.0 Add-In, which allows for inserting line numbers throughout my Code. This works great, but has to be triggered manually each time I modify the code.

    So, I attempted to automate this together with each time the project is compiled:

    'Automatisches Kompilieren des Projekts (wird vor dem Speichern ausgeführt) (Nebenprozedur)
    Sub subProjektAutomatischKompilieren()
    
         On Error GoTo Fehlerbehandlung
        
            'Excel Verhalten setzen
            With Application: .ScreenUpdating = False: .EnableEvents = False: End With
             
            'Lokale Variablen dimensionieren/speichern
            Dim objVBEMenüBar As Object
            Dim objKompilieren As Object
            Set objVBEMenüBar = Application.VBE.CommandBars
            
            'Projekt kompilieren falls Code verändert wurde
            Set objKompilieren = objVBEMenüBar.FindControl(Type:=msoControlButton, ID:=578)
            If objKompilieren.State = msoButtonUp Then
                objKompilieren.Execute
    '            Set objKompilieren = objVBEMenüBar.FindControl(Type:=msoControlButton, Tag:="AddLineNumbers")
    '            objKompilieren.Execute
            End If
            
            'Excel Verhalten setzen
            With Application: .EnableEvents = True: .ScreenUpdating = True: End With
    
    
        Exit Sub
    
    
    Fehlerbehandlung:
    
    
        'Excel Verhalten setzen
        With Application: .EnableEvents = True: .ScreenUpdating = True: End With
        
        'Fehler verursachen (wird im Anschluss in der Hauptprozedur gespeichert)
        Err.Raise Err.Number, " | subProjektAutomatischKompilieren", Err.Description
    
    
    End Sub
    The two relevant lines of code are highlighted in bold.
    This procedure works for adding line numbers to itself, but not throughout the whole project.

    Any ideas or other ways to add line numbers?

    Kind regards

  2. #2
    Have you updated to the Aug 1 release? Add/Remove line numbers was added to the right click context menu to make it more convenient.

  3. #3
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location
    Thanks for your reply, I've got the latest release. Sure I can do it manually, but the goal is to let VBE handle this for me upon compiling the project.

    When doing it "manually", the MZ-Tools asks if I want to apply the lines to the current procedure/module or project; and the default seems to be procedure level.

    So, my question is if there is a way to add parameters/options to change the scope of the procedure to project-level

  4. #4
    Honestly, I think you would be better off contacting Carlos Quintero directly

    https://www.mztools.com/contact.aspx


    He's been pretty responsive the couple of times I've sent a question.

    Or just spend $20 and get the AET VBE Tools add-in which has a nice "add to project" context menu pick to add lines to the entire project all in one go.

    https://sites.fastspring.com/andrews...ct/aetvbetools

  5. #5
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location
    I've purchased MZ-Tools for about 70$, so definitely I'm not going to buy a redundant add-in

    Mhmm I'm not sure...I've contacted MZ-Tools support already, and they answered that it is not possible. But since it is feasible for a single sub, i was wondering...
    Last edited by nikki333; 11-18-2018 at 03:20 PM.

  6. #6
    Quote Originally Posted by nikki333 View Post
    I've purchased MZ-Tools for about 70$, so definitely I'm not going to buy a redundant add-in
    Your choice of course, but I have both and think the AET tools are worth $20. There are a couple of functions there that plug some gaps in MZ Tools.

    You can always just code you own solution to add line numbers. Should not be too hard.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •