devxlogo

Print a Single Sub or Function

Print a Single Sub or Function

Need a fast way to print only one sub or function in VB3 that also takes care of the problem some printers have in printing the last page?Create a small form with one command button. Change the button’s Caption to Print Sub. Add this code to the button’s Click event:

 Sub Command1_Click ()	'Make sure VB has the focus.	AppActivate "Microsoft Visual Basic"	'Clear the Clipboard just in case.	Clipboard.Clear	'Select the Sub or Function and copy	'it to the Clipboard.	SendKeys "^{HOME}" & "^+{END}" & "%EC", True	'Print the Clipboard	Printer.Print Clipboard.GetText ()	'Form Feed in case printer needs it	'to print the last page.	Printer.NewPage	'End the print job.	Printer.EndDoc	'Unmark the Sub or Function.	SendKeys "{HOME}", TrueEnd Sub

Move the form to a spot you want it to appear in when running. Compile it to an EXE file. Run it along with Visual Basic. When you want to print a sub or function, make sure the cursor is in the Sub or Functions code box, and click on the Print Sub button.Printer.EndDoc called immediately after Printer.NewPage ensures that no blank page is printed.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist