Top Banner
Macros For Reflections Christopher Guertin VAMC – West Palm Beach, FL [email protected] 1
67
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

1

Macros For Reflections

Christopher GuertinVAMC – West Palm Beach, [email protected]

Page 2: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

2

Define what a Macro is Tell the differences between VB and

VBA Record a Macro Edit a Recorded Macro Create a Macro Explain when and why we would use

a Macro in Reflections

Objectives

Page 3: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

3

Macro (noun) Webster Dictionary a single computer instruction that

stands for a sequence of operations Sometimes referred to as:

Macroinstruction

What is a Macro

Page 4: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

4

VB – Visual Basic

Standalone Can be used complied

into an executable and run outside the host

Uses same syntax as VBA

VBA- Visual Basic For Applications

Requires an Application

Reflections Excel Word Access

Is complied and run within inside the host only

Uses same Syntax as VB

VB vs VBA

Page 5: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

5

Saves Times Consistent Data Easy to make both minor and major

changes Exportable / Importable Multiple + Easier to use interfaces Allows for User Input Software Already Available

Why use a Macro

Page 6: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

6

Automating almost anything Mouse, Keyboard, Options on Menu

Creating Dialog Boxes or User Forms Passing Data Between Applications Error Checking and Handling

What a Macro Can Do

Page 7: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

7

Examples: Change Screen Fonts, Color, Size Assign Functions to Keys Allow User Input for Fileman Reports Allow Fileman Reports to be Dynamic Clean up “Dirty Data” Complete Repetitive Tasks Works well with Fileman Transfer Data to/from MS Office Products No Programmer Access Required

Benefits of Macros for Reflections

Page 8: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

8

DO NOT put your username or password into a macro to use as an AutoLogin

Code Entered is generally not considered Encrypted

Security

Page 9: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

9

Sample Reflections Screen

Page 10: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

10

Must start with letter May Contain Numbers, Letters May use an Underscore 80 Character Max No Special Characters or Spaces

Example: INPT_WORKLOAD_2011

Naming a Macro

Page 11: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

11

Macro Start Recording

Stop, Pause, Annotate

Can Edit, Create button, Map to key

How to Record

Page 12: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

12

Macro Macros Edit

How to Edit Macro

Page 13: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

13

Macro Macros Type in name under Macro Name:

Creating Macro

Page 14: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

14

Setup Keyboard Map

Assigning Macro to Key

Page 15: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

15

Setup Mouse Map

Assigning Macro to Mouse Button

Page 16: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

16

Right Click Tool Bar

Setup Toolbars Customize New Button

After Recording – Check – Create Button

Assigning to Button on Toolbar

Page 17: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

17

Customizing Buttons

Page 18: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

18

Macro Stop Macro Ctrl+Break Create a Button

Stopping a Macro

Page 19: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

19

File Save As

Saving Macro

Page 20: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

20

Setup Toolbar… Settings

Saving Tool Bars

Page 21: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

21

VBA – Adding to MS Office Products

Page 22: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

22

Customize Quick Access Toolbar More Commands Customize

Customize Quick Access Toolbar

Page 23: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

23

Tools References

Adding / Removing Object Libraries

Page 24: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

24

Wait for Input into Reflections Message Box to Help

Input Box User Form

User Input

Page 25: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

25

Message Box

Page 26: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

26

Input Box

Page 27: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

27

User Form

Page 28: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

28

Could be a course all by itself Many Options

Label Text Box Combo Box List Box

User Form

Page 29: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

29

User Form - WYSIWYG

Page 30: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

30

User Form – How the User Sees It

Page 31: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

31

Converts Date to Format Useable by VISTA

Date Converter

Page 32: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

32

Format() Format(expression[, format[, firstdayofweek[, firstweekofyear]]])

strDate = Format(strDate, "dddd, mmm d yyyy") Wednesday, Aug 3 2011

MyStr = Format(strTime, "hh:mm:ss AMPM") 05:14:03 AM

Format Date / Time

Page 33: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

33

Operators Arithmetic

+, -, *, / Comparison

>, < , = Concatenation

&, + Logical

And, Not, Or

Expressions

Page 34: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

34

Variables Naming

Must start with letter Can be up to 255 characters Cannot contain a Space but can use

underscore Cannot contain Operators or Special

Characters

Variables

Page 35: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

35

Should be declared Procedure

Only for that Procedure Automatically declared Dim strDRUG as String

Private All Procedures in the Module Private strDRUG as String

Public All Procedures in All Modules of Project Public strDRUG as String

Variable Life

Page 36: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

36

VB Codes

Page 37: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

37

Ascii Codes

Page 38: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

38

Message Box

Page 39: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

39

If - Then If – Then – Else If – Then – ElseIf – Else GoTo Select Case

Statements

Page 40: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

40

For – Next For Each – Next Do While – Loop Do – Loop While While – Wend Do Until – Loop Do – Loop Until

Loops

Page 41: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

41

Comparison Operators

Page 42: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

42

Logical Operators

Page 43: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

43

Format Transmit WaitForString Ucase Lcase

Able to create your own Allows for only one set of code(refer to

it)

Functions

Page 44: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

44

‘ Apostrophe for comment(will not run)

Comment Top: User, Date, Explain Function After Code

Declare Variables at Top TALLman Lettering

Use Error Handler Try to make more universal

Good Habits

Page 45: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

45

Create in Test Account if possible Be careful and use checks when user

will be creating orders Validate Data

Good Habits

Page 46: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

46

Create Buttons to Change Column Size

Switch Column Size

Page 47: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

47

Screen Capture to Text FileLogging On/Off

Page 48: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

48

Differentiate Screens Allows users to easily change to

preferred color scheme

Changing the Color of the Screen

Page 49: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

49

Macro Macros Select from list and click Run

How to Run Macro

Page 50: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

50

Click on Button Created

Run a Macro

Page 51: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

51

From a Macro you can Load a User Form-Auto-Populate Fields Then Send User Input back to Original Macro

Code Behind the User Form

Page 52: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

52

The Code will start running and user input will be requested as needed

Macro has Started

Page 53: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

53

Many Input boxes can be used or one user form

Default Values may be set

User Input

Page 54: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

54

Many Input boxes can be used or one user form

Default Values may be set

User Input

Page 55: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

55

The user input is captured and then added to the Fileman routine

The user input is then used

Page 56: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

56

The routine appears to be done but more actions are preformed in the background

May have a final stop to allow it to be aborted

The routine is run

Page 57: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

57

What is happening Behind the Scenes

Page 58: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

58

The Results from the Macro

Page 59: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

59

Shawn Toy Created an Amazing Add-In for Excel that will allow text that wraps to be flattened out

http://vaww.infoshare.va.gov/sites/vapharmacyinformatics/WIKI/FileMan/FileMan_TextCapture_Tools.aspx

From .TXT to Excel

Page 60: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

60

Add-In FileMan Tools File Import Interm

How to use Add-In

Page 61: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

61

Easy as 1, 2, 3

Delimited Data

Page 62: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

62

The header will confirm when it was run and what user input was entered

The data can be copied over to a new sheet or the top part can be deleted to make the headers active

The Final Results

Page 63: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

63

Can be useful to learn Syntax and Concepts

Help File

Page 64: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

64

Help File

Methods Properties Events

Page 65: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

65

Pharmacy ADPAC Email Group Visual Basic Books / References VBA Books Google SharePoint (Future)

More Help

Page 66: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

66

SharePoint Sitehttp://vaww.infoshare.va.gov/sites/vapharmacyinformatics/WIKI/

VBA/Home.aspx

Share Design Ideas Integrate Fileman Routines Seamless Data Transfer to MS Office

Products VBA / Macro Education Series

Reflections MS Office

The Future

Page 67: Christopher Guertin VAMC – West Palm Beach, FL Christopher.Guertin@VA.GOV 1.

67

Questions