8
Macro’s Within excel

Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the

Embed Size (px)

Citation preview

Page 1: Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the

Macro’sWithin excel

Page 2: Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the

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.

Page 3: Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the

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

Page 4: Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the

Printing with VBA

Sub CreatePrint()

This part creates the sub-routine CreatePrint()

Page 5: Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the

Printing with VBA

Dim answer As Integer

We are now defining answer as an integer.

Page 6: Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the

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).

Page 7: Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the

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.

Page 8: Macro’s Within excel. Most functionality can be driven from VBA VBA is the programming language that runs inside of excel. It uses visual basic as the

Printing with VBA

End Sub

Then we end the subroutine so the computer does not get confused between all the Macro’s code.