12
OV 3 - 1 ght © 2011 Element K Content LLC. All rights reserved. Determine the Dialog Box Type Capture User Input Creating an Interactive Worksheet

OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved. Determine the Dialog Box Type Capture User Input Creating an Interactive Worksheet

Embed Size (px)

Citation preview

Page 1: OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet

OV 3 - 1Copyright © 2011 Element K Content LLC. All rights reserved.

Determine the Dialog Box Type Capture User Input

Creating an Interactive Worksheet

Page 2: OV 3 - 1 Copyright © 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

Page 3: OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet

OV 3 - 3Copyright © 2011 Element K Content LLC. All rights reserved.

Input Boxes

Title bar textTitle bar text

MessageMessage ButtonsButtons

Default textDefault text

Page 4: OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet

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

Page 5: OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet

OV 3 - 5Copyright © 2011 Element K Content LLC. All rights reserved.

Const CompanyName As String = “Our Global Company”

Constants

Page 6: OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet

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

Page 7: OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet

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

Page 8: OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet

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

Page 9: OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet

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

Page 10: OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet

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

Page 11: OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet

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

Page 12: OV 3 - 1 Copyright © 2011 Element K Content LLC. All rights reserved.  Determine the Dialog Box Type  Capture User Input Creating an Interactive Worksheet

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