Upload
arline-hubbard
View
212
Download
0
Embed Size (px)
Citation preview
OV 3 - 1Copyright © 2011 Element K Content LLC. All rights reserved.
Determine the Dialog Box Type Capture User Input
Creating an Interactive Worksheet
OV 3 - 2Copyright © 2011 Element K Content LLC. All rights reserved.
Message Boxes
Buttons for capturingusers’ responses
Buttons for capturingusers’ responses
MessagesMessages
OV 3 - 3Copyright © 2011 Element K Content LLC. All rights reserved.
Input Boxes
Title bar textTitle bar text
MessageMessage ButtonsButtons
Default textDefault text
OV 3 - 4Copyright © 2011 Element K Content LLC. All rights reserved.
InputBox(Message, TitlebarTxt, DefaultTxt)
The InputBox Function
Default textDefault text
Title bar textTitle bar text
MessageMessage
OV 3 - 5Copyright © 2011 Element K Content LLC. All rights reserved.
Const CompanyName As String = “Our Global Company”
Constants
OV 3 - 6Copyright © 2011 Element K Content LLC. All rights reserved.
The MsgBox Function
MsgBox(Message, vbYesNo)
Constant which determines the types of buttons
Constant which determines the types of buttons
Variable containing the message
Variable containing the message
OV 3 - 7Copyright © 2011 Element K Content LLC. All rights reserved.
The Code Continuation Character
Command runs off right marginCommand runs off right margin
Command broken on several lines
Command broken on several lines
Long command on one line of code
Long command on one line of code
Code continuation character used at the end of each lineCode continuation character used at the end of each line
OV 3 - 8Copyright © 2011 Element K Content LLC. All rights reserved.
The vbCrLf Character
Text displayed in the message
box with line breaks
Text displayed in the message
box with line breaks
Message = "Enter a number to sort by the following fields:" & vbCrLf & _"1 –- By Date and Time" & vbCrLf & _"2 -- By Customer Service Rep, Date, and Time"
vbCrLf character used to indicate
line breaks
vbCrLf character used to indicate
line breaks
OV 3 - 9Copyright © 2011 Element K Content LLC. All rights reserved.
Decision Structures
Select Case UserResponseCase “1” MsgBox (Message1, vbYesNo)Case “2” MsgBox (Message2, vbYesNo)Case Else MsgBox (ErrMsg, vbYesNo)End Select
Comparative data valuesComparative data values
Criterion variableCriterion variable
If UserResponse = 2 Then
MsgBox(Msg1, vbYesNo)
EndIf
Criterion expressionCriterion expression
Code that runs depending on the criteria
Code that runs depending on the criteria
Code blocks that perform different actions based
on criteria
Code blocks that perform different actions based
on criteria
OV 3 - 10Copyright © 2011 Element K Content LLC. All rights reserved.
The Select Case Structure
Select Case UserResponseCase “1” MsgBox (Message1, vbYesNo)Case “2” MsgBox (Message2, vbYesNo)Case Else MsgBox (ErrMsg, vbYesNo)End Select
Beginning of the Select Case structure
Beginning of the Select Case structure
Comparative data valuesComparative data values
Criterion variableCriterion variable
Code that runs depending on the value in
criterion variable
Code that runs depending on the value in
criterion variable
End of the Select Case structure
End of the Select Case structure
Case Else statementCase Else statement
Case statementsCase statements
OV 3 - 11Copyright © 2011 Element K Content LLC. All rights reserved.
The If Then Structure
If UserResponse = 2 Then
MsgBox(Msg1, vbYesNo)
EndIf
If Then statementIf Then statement
Criterion expressionCriterion expression
End If statementEnd If statement
Code to run if criterion metCode to run if criterion met
OV 3 - 12Copyright © 2011 Element K Content LLC. All rights reserved.
1. How can the use of input boxes and message boxes change the way you use Excel? Explain with examples.
2. Give examples of input that you may gather from a user to be used in a macro.
Reflective Questions