Upload
maurice-newman
View
234
Download
0
Embed Size (px)
Citation preview
Macro’sWithin excel
Most functionality can be driven from VBAVBA is the programming language that runs inside of excel. It uses visual basic as the core as it stands for visual basic application.
Printing with VBA
Sub CreatePrint() Dim answer As Integer answer = MsgBox("Are you sure you want to print sheet?", vbYesNo + vbQuestion, "Print Sheet") If answer = vbYes Then ActiveSheet.PrintOut Else 'do nothing End If End Sub
Printing with VBA
Sub CreatePrint()
This part creates the sub-routine CreatePrint()
Printing with VBA
Dim answer As Integer
We are now defining answer as an integer.
Printing with VBA
answer = MsgBox("Are you sure you want to print sheet?", vbYesNo + vbQuestion, "Print Sheet")
We then are saying that the value of answer is equal to a response from a MsgBox (a pop-up dialog).
Printing with VBA
If answer = vbYes Then
ActiveSheet.PrintOut
Else
'do nothing
End If
We now need to make sure the users meant to print and we can do so with their response and this if statement.
It checks to see if the dialog response was yes and if it was, it prints the sheet.
If it was no, it does nothing. The “’do nothing” is a comment, this is not actually processed it just helps us.
Printing with VBA
End Sub
Then we end the subroutine so the computer does not get confused between all the Macro’s code.