Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making...

10
www.durhamcountync.gov Durham County Government Durham County Government A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier Presented By: Kevin Etheridge, Budget Analyst NC Local Government Budget Association Winter Conference December 13, 2007

Transcript of Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making...

Page 1: Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier Presented By: Kevin Etheridge, Budget.

www.durhamcountync.gov

Durham County GovernmentDurham County Government

A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier

Presented By: Kevin Etheridge, Budget Analyst

NC Local Government Budget AssociationWinter ConferenceDecember 13, 2007

Page 2: Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier Presented By: Kevin Etheridge, Budget.

www.durhamcountync.gov

Durham County GovernmentDurham County Government

What are macros?Programming used to automate tasks which are often repetitive or complex in nature

What are the dangers of macros?Macros from unknown sources may contain malicious code.

What are the benefits of macros?The automation of tasks can save time and ensure accuracy.

Are macros for novices?They can be learned through a combination of tutorials, Googling, patience, and trial and error.

What are some of the uses for budgeting?Formatting changes, changes across multiple workbooks, forms, and much more

Page 3: Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier Presented By: Kevin Etheridge, Budget.

www.durhamcountync.gov

Durham County GovernmentDurham County Government

Macro Security

Tools

Macros

Security

Page 4: Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier Presented By: Kevin Etheridge, Budget.

www.durhamcountync.gov

Durham County GovernmentDurham County Government

Recording A Simple Macro

On the Tools Menu:Select Macro ->Record New Macro

You will asked to name your macro and assign a keyboard shortcut

Perform the desired functions and then click on the ■ icon.

Page 5: Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier Presented By: Kevin Etheridge, Budget.

www.durhamcountync.gov

Ex: Sort Worksheets in a Workbook

1. Copy macro

2. Tools Macro Visual

Basic Editor

3. Insert Module

4. Paste macro

5. Save and/or run.

Warning: know and trust the source of the macro!

Page 6: Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier Presented By: Kevin Etheridge, Budget.

www.durhamcountync.gov

Durham County GovernmentDurham County Government

Sub SortWorksheets()' sort worksheets in a workbook in ascending orderDim sCount As Integer, i As Integer, j As Integer

Application.ScreenUpdating = False sCount = Worksheets.Count If sCount = 1 Then Exit Sub

For i = 1 To sCount - 1 For j = i + 1 To sCount

If Worksheets(j).Name < Worksheets(i).Name Then Worksheets(j).Move Before:=Worksheets(i)

End If Next j

Next iEnd Sub

Page 7: Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier Presented By: Kevin Etheridge, Budget.

www.durhamcountync.gov

Sub ProcessFiles()Application.EnableEvents = FalseApplication.DisplayAlerts = FalseDim i As LongDim sFolder As StringDim fldr As ObjectDim FSO As ObjectDim Folder As ObjectDim file As ObjectDim Files As ObjectDim this As WorkbookDim cnt As Long Set FSO = CreateObject("Scripting.FileSystemObject") Set this = ActiveWorkbook sFolder = "S:\SHARE\BUDGET\06-07 Budget Document\Number Sections" If sFolder <> "" Then Set Folder = FSO.GetFolder(sFolder) Set Files = Folder.Files cnt = 1 For Each file In Files If file.Type = "Microsoft Excel Worksheet" Then Workbooks.Open Filename:=file.Path With ActiveWorkbook Sheets("Sheet1").Select ActiveWindow.DisplayGridlines = False Columns("F:F").Hidden = True Columns("G:G").Hidden = False Range("F6:F6").Select Selection.Interior.ColorIndex = xlNone ActiveWorkbook.Close SaveChanges:=True End With cnt = cnt + 1 End If Next file End If ' sFolder <> ""Application.EnableEvents = TrueApplication.DisplayAlerts = TrueEnd Sub

Ex: Change All Files in a Folder

Replace the red text with your file path.

Replace the red text with the actions you want performed.

Page 8: Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier Presented By: Kevin Etheridge, Budget.

www.durhamcountync.gov

Durham County GovernmentDurham County Government

Page 9: Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier Presented By: Kevin Etheridge, Budget.

www.durhamcountync.gov

Durham County GovernmentDurham County Government

Page 10: Www.durhamcountync.gov Durham County Government A Brief Intro. To Microsoft Excel Macros: Making Life A Little Easier Presented By: Kevin Etheridge, Budget.

www.durhamcountync.gov

Durham County GovernmentDurham County Government

Resources on Macros

http://www.exceltip.com/category.html#6

http://exceltips.vitalnews.com/E090_VBA_Examples.html

http://www.cpearson.com/excel/mainpage.aspx

Your local library