5

How do I programmatically print source code in a VB6 Addin..? There are no print or preview methods that I can find for VBIDE in the Object Browser.

I've searched high & low on Google, and there's a strange lack of information on VBIDE code module printing. I get lots of hits for PrettyPrint, but that's all. The lack is so great that it makes me wonder if there's some fundamental concept that I'm completely missing.

I scared up a copy of the O'Reilly book mentioned by Herb in https://stackoverflow.com/a/41034211/2705042, and it makes no mention of the printing of source code. The only way I can see is to export the code to text files and print those through usual means unrelated to VBIDE.

I also checked Chip Pearson's guide to VBE at http://www.cpearson.com/excel/vbe.aspx, which is almost identical to VBIDE, and even there is no clue to printing of code, other than the idea I mentioned of saving to text files and then printing.

** Ideally, I'd like to use the existing VB6 File > Print dialog, with one extra checkbox added to it. I realize the addition of controls to an existing dialog is another topic, and I'm not averse to creating my own version of the print dialog.

Community
  • 1
  • 1
spinjector
  • 3,121
  • 3
  • 26
  • 56
  • VB6 allows you to toggle options for printing "pretty" using File->Print . Generally, it is better to just have your code "pretty" in the first place for print. If you want something more elaborate, you can try this [VB.Print - Source code printing utility](https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=9493&lngWId=1) from Planet-Source-Code – Kraang Prime Dec 26 '16 at 23:18
  • Printing pretty has nothing to do with the addin I'm creating. The primary purpose is simply to send each subroutine or function to the printer as an individual print job. This is to make use of the stapler that our office printer has, so each procedure comes out already stabled. It keeps things wonderfully organized. I've synthesized a workaround of sorts for my issue: I'm using VBIDE to directly access the text in the code modules, to copy each procedure into a string variable, and then sling that at the printer. But I might still like to use a built-in print function - if I could find one. – spinjector Dec 27 '16 at 20:30
  • It has been some time since I played around with VB6 addin writing, but I understand the concept. I believe `mztools` might already have procedural printing, however I don't recall. Pretty sure there isn't anything that will just grab all methods and print them each as individual jobs. Sadly, VB6 codes are scarce these days and VB6 plugin code even more rare. If I come across anything relevant I can post it -- but If it was me, I would write this as a separate project (maybe build on that Planet Source Code app) to hack it into doing that specific job. – Kraang Prime Dec 27 '16 at 20:34

1 Answers1

2

It is possible with a CommandBarButton proxy and SendKeys.

Getting a handle to the Print CommandBarControl is simple enough, but pressing the button throws a dialog in your way, so we have to use SendKeys to set the options and submit the form....

You can use code similar to the following:

Dim printCommand As CommandBarControl
Set printCommand = Application.VBE.CommandBars.FindControl(ID:=4)

printCommand.Execute

'Yep, SendKeys, erghhh
Application.SendKeys "P" 'Force the whole project to print
Application.SendKeys "{ENTER}"
ThunderFrame
  • 9,352
  • 2
  • 29
  • 60