Trying to run Module from a button

andrewkoemm

New member
Local time
Today, 13:39
Joined
May 7, 2015
Messages
8
I have created a module that runs a print screen command. The module runs great when I run it from the VBA window. But I do not know how to run the command from a button so that it can take a screen shot of the form.

Here is my code below:
PS.PNG
 
I have created a module that runs a print screen command. The module runs great when I run it from the VBA window. But I do not know how to run the command from a button so that it can take a screen shot of the form.

Here is my code below:
View attachment 58380

If you go to the properties of the button on the form you can locate the On Click Event property. From there you can set the code to run when the button is clicked.

Not sure if it can reference the Private sub, so if you have strange errors that could be it.

Wish I had more for you, but I wanted to at least give you something until someone else can chime in. Good luck.
 
Sorry that did not work. Before i posted this thread i spend an hour searching through Google and trying different approaches, with no progress.
 
Create a Public function that does something simple and see if you can run it using the On Click Event of the button. If so, then it's possible that your Private function can't be called or it could be something else. Try moving your code into a Public function if possible.
 
Does it matter if its a sub or function? I have it as a sub.

Is this what you are tell me to do:

Call.PNG
 
Does it matter if its a sub or function? I have it as a sub.

Is this what you are tell me to do:

View attachment 58384

Sorry about my wording, just a Public sub is what I meant.

Instead of using the "Expression Builder" click on "Code Builder" when selecting the on click event property. From there type something simple like
Code:
MsgBox "It works!?"
in the sub and see what happens when you click your button.
 
Ok that simple code worked. So what am I doing wrong when I am trying to implement my screen shot code.
 
Did you try to copy and paste the AltPrintScreen sub into the On Click sub you just created? Replace the "MsgBox" code with that and see if it works or returns errors.
 
Keep your original code, and ONLY place the AltPrintScreen portion in the On Click sub.

Beyond that, I'm not sure how much help I can be, but I'm sure someone else on here can.
 
Sorry no progress. :banghead:

Hopefully someone else will be able to assist.
Thanks for the help.
 
Sorry no progress. :banghead:

Hopefully someone else will be able to assist.
Thanks for the help.

You're welcome. If it's urgent I would recommend to create a new thread with a link to this one and explain it's urgency. This thread has a possibility of being buried.
 
You cannot embed subs. You can call other subs but the code cannot be contained in the original Sub.
 

Users who are viewing this thread

Back
Top Bottom