Print A Single Sub Or Function

Print A Single Sub Or Function

The problem? You want to print a single sub but VB always prints allthe subs that are in the current form. You could copy it to the clipboardand print it with the MS-Editor or Notepad. You could buy expensive toolsto do this seemingly simple task. Here’s a less annoying solution to theproblem. Generate a small form. Add a command button. The caption may be”Print Sub.” Then, add this code to the module:

 Sub Command1_Click ()	' Make sure that VB has the focus	AppAcitvate "Microsoft Visual Basic"	' Move the cursor to the upper left corner. 	' The sub can contain a maximum of 500 lines.	' send SHIFT together with the DOWN key 	' to mark the whole sub.SendKeys "{Home}{UP 500} + ({DOWN 500}) % (EC)", True 	' Copy SUB to the clipboardPrinter.Print Clipboard.GetText()	' Print ClipboardPrinter.EndDoc	' Un-mark the SUBSendKeys "{HOME}"End Sub

Generate the EXE and run it together with VB. Move the Print-Sub formto a convenient desktop position. If you want a single sub of your project to be printed, set the cursorto any position in this SUB and click on the Print-Sub button. I’ve tested the code with VB3 Pro. In other VB Versions (such as theGerman Standard edition) you might have to change the “%(EC)”portion. “EC” refers to the VB menu bar.


Share the Post: