PDA

View Full Version : [SOLVED] Adding line numbers to VBE Code using MZ-Tools



nikki333
11-18-2018, 08:29 AM
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

rlv
11-18-2018, 11:05 AM
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.

nikki333
11-18-2018, 12:29 PM
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

rlv
11-18-2018, 01:48 PM
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/andrewsexceltips/product/aetvbetools

nikki333
11-18-2018, 02:45 PM
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...

rlv
11-18-2018, 03:36 PM
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.