SlideShare a Scribd company logo
Bonus Chapter 2
TenVBATipsandTricks
In This Chapter
ᮣ Using helpful habits
ᮣ Making your work more efficient
This chapter contains a list of ten clever tricks I’ve developed (or acquired
from other users) over the years.
Getting VBA Help, Fast
When working in a VBA module, you can get instant help regarding a VBA
object, property, or method. Just move the cursor to the word that interests
you and press F1.
Speeding Up Your Macros
If you write a VBA macro that produces lots of on-screen action, you can
speed things up significantly by turning off screen updating. To do so, exe-
cute this statement:
Application.ScreenUpdating = False
If your macro uses a custom dialog box, make sure to turn screen updating
back on before displaying the UserForm. Otherwise, moving the dialog box
on the screen leaves an ugly trail.
2 Excel VBA Programming For Dummies
Avoiding Excel’s Questions
Some VBA methods cause Excel to display a confirmation message,
which requires the user to click a button. For example, the statement
ActiveSheet.Delete always displays a dialog box that asks for confirmation.
To eliminate such confirmation messages, execute the following before the
statement that causes the confirmation messages.
Application.DisplayAlerts = False
Use this statement to reinstate the confirmation messages:
Application.DisplayAlerts = True
Displaying One Procedure at a Time
Normally, a Code window in the Visual Basic Editor (VBE) shows all the pro-
cedures in the module, one after another. If you find this distracting, set
things up so that only one procedure is visible.
1. Activate the VBE and choose Tools➪Options.
2. Click the Editor tab in the Options dialog box.
3. Remove the check mark from the Default to Full Module View
check box.
Then you can use the drop-down lists at the top of the module window to
select the procedure to view or edit.
Using With-End With
If you need to set a number of properties for an object, your code is easier to
read and faster running if you use the With-End With construct. The following
code doesn’t use With-End With:
Selection.HorizontalAlignment = xlCenter
Selection.VerticalAlignment = xlCenter
Selection.WrapText = True
Selection.Orientation = 0
Selection.ShrinkToFit = False
Selection.MergeCells = False
3Bonus Chapter 2: Ten VBA Tips and Tricks
The next code performs the same action but is rewritten to use With-End
With:
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.ShrinkToFit = False
.MergeCells = False
End With
Reducing the Size of a Workbook
In many cases, you can significantly reduce the size of a workbook —
especially a workbook with modules you’ve heavily edited — because Excel
does not do a good job of cleaning up after itself. To clean up the mess
Excel leaves behind:
1. Save your workbook.
2. Select a module or a UserForm in the Project Window.
3. Right-click and choose Remove from the shortcut menu.
4. When asked whether you want to export the module, click Yes.
5. Repeat Steps 3 and 4 for each module and UserForm, keeping track of
the modules and forms that you remove.
6. Choose File➪Import File to import all the modules and forms you
deleted.
7. Save your workbook again.
You usually find that the new workbook is much smaller than it was.
Another way to reduce the size of a workbook file is as follows:
1. Activate your workbook.
2. Choose File➪Save As Web Page, and make sure that you use the
Entire Workbook option.
3. Close your workbook.
4. Use File➪Open to open the HTML file that you saved in Step 2.
5. Use File➪Save As, and resave the workbook as a standard XLS file.
In most cases, you’ll find that the file is smaller in size.
4 Excel VBA Programming For Dummies
Bypassing a Workbook_Open Procedure
Workbook_Open is a macro that Excel executes automatically when you open
a workbook. In some situations, you may want to avoid running this macro.
To do so, press the Shift key while opening the workbook.
Using Your Personal Macro Workbook
If you’ve developed some general-purpose macros, consider storing them in
your Personal Macro Workbook, which opens automatically whenever Excel
starts. When you record a macro, you have the option of recording it to your
Personal Macro Workbook. The file, PERSONAL.XLS, is stored in your
XLSTART directory. The Personal Macro Workbook is created the first time
you record a macro to it.
The Personal Macro Workbook is hidden by default.
Displaying Messages in the Status Bar
If you develop a lengthy macro, use the Excel status bar to display text that
describes the progress of the macro. To do so, write some code that periodi-
cally executes another macro, such as the following:
Sub UpdateStatusBar(PctDone)
Application.StatusBar = _
“Percent Completed: “ & Format(PctDone, “0%”)
End Sub
This procedure uses one argument: a value that ranges from 0 to 1.0. The
macro simply displays a message that indicates the percent completed. To
return the status bar back to normal, execute the following statement:
Application.StatusBar = False
Forcing Yourself to Declare All Variables
Declaring every variable that you use in your code is an excellent practice.
For example, if you use an integer variable named Count, declare it as Dim
Count as Integer.
Declaring your variables as a particular data type makes your code run faster
and also helps avoid typographical errors. To force yourself to declare all
variables, insert the following statement at the top of your module:
Option Explicit
If you would like this statement automatically added to each new module,
follow these steps:
1. Activate the VBE and choose Tools➪Options.
2. In the Options dialog box, click the Editor tab.
3. Place a check mark next to Require Variable Declaration.
5Bonus Chapter 2: Ten VBA Tips and Tricks
6 Excel VBA Programming For Dummies

More Related Content

What's hot

RapidResponse Autoresponder Quick Start Guide Pictorial
RapidResponse Autoresponder Quick Start Guide Pictorial RapidResponse Autoresponder Quick Start Guide Pictorial
RapidResponse Autoresponder Quick Start Guide Pictorial
Phil Eugene
 
Microsoft Office 2003 Creating Macros
Microsoft Office 2003 Creating MacrosMicrosoft Office 2003 Creating Macros
Microsoft Office 2003 Creating Macros
S Burks
 
Salesforce Admin Hacks
Salesforce Admin HacksSalesforce Admin Hacks
Salesforce Admin Hacks
Joshua Loomis
 
How to add the windows calculator to the quick access toolbar in microsoft ex...
How to add the windows calculator to the quick access toolbar in microsoft ex...How to add the windows calculator to the quick access toolbar in microsoft ex...
How to add the windows calculator to the quick access toolbar in microsoft ex...Trường Tiền
 
Using splunk6.2 labs
Using splunk6.2 labsUsing splunk6.2 labs
Using splunk6.2 labs
Jagadish a
 
VISUAL
VISUALVISUAL
VISUAL
emi kenye
 
REmote server
REmote serverREmote server
REmote server
Darnette A
 
Excel 2007 Unit I
Excel 2007 Unit IExcel 2007 Unit I
Excel 2007 Unit I
Raja Waseem Akhtar
 

What's hot (12)

RapidResponse Autoresponder Quick Start Guide Pictorial
RapidResponse Autoresponder Quick Start Guide Pictorial RapidResponse Autoresponder Quick Start Guide Pictorial
RapidResponse Autoresponder Quick Start Guide Pictorial
 
Microsoft Office 2003 Creating Macros
Microsoft Office 2003 Creating MacrosMicrosoft Office 2003 Creating Macros
Microsoft Office 2003 Creating Macros
 
My power point macros
My power point macrosMy power point macros
My power point macros
 
Vba 2 (students copy)
Vba 2 (students copy)Vba 2 (students copy)
Vba 2 (students copy)
 
Salesforce Admin Hacks
Salesforce Admin HacksSalesforce Admin Hacks
Salesforce Admin Hacks
 
How to add the windows calculator to the quick access toolbar in microsoft ex...
How to add the windows calculator to the quick access toolbar in microsoft ex...How to add the windows calculator to the quick access toolbar in microsoft ex...
How to add the windows calculator to the quick access toolbar in microsoft ex...
 
Using splunk6.2 labs
Using splunk6.2 labsUsing splunk6.2 labs
Using splunk6.2 labs
 
Chapter 9
Chapter 9Chapter 9
Chapter 9
 
VISUAL
VISUALVISUAL
VISUAL
 
REmote server
REmote serverREmote server
REmote server
 
Excel 2007 Unit I
Excel 2007 Unit IExcel 2007 Unit I
Excel 2007 Unit I
 
Lesson2
Lesson2Lesson2
Lesson2
 

Viewers also liked

Question words (wh & how)
Question words (wh & how)Question words (wh & how)
Question words (wh & how)
Marcos_L
 
Tecnologia educativa
Tecnologia educativaTecnologia educativa
Tecnologia educativasoleflor
 
resume_Malik Ross_IV Pharmacy Technician Hospital-Home Infusion 053115
resume_Malik Ross_IV  Pharmacy Technician Hospital-Home Infusion 053115resume_Malik Ross_IV  Pharmacy Technician Hospital-Home Infusion 053115
resume_Malik Ross_IV Pharmacy Technician Hospital-Home Infusion 053115Malik Ross
 
Deals2nitefinalpresentation
Deals2nitefinalpresentationDeals2nitefinalpresentation
Deals2nitefinalpresentationBobHalo21
 
Statement of purpose
Statement of purposeStatement of purpose
Statement of purpose
kapil baral
 
Sample SoP for MBA Application Sample
Sample SoP for MBA Application SampleSample SoP for MBA Application Sample
Sample SoP for MBA Application Sample
MBA Statement of Purpose Samples
 
FPGA FIR filter implementation (Audio signal processing)
FPGA FIR filter implementation (Audio signal processing)FPGA FIR filter implementation (Audio signal processing)
FPGA FIR filter implementation (Audio signal processing)
Hocine Merabti
 
Mpls basic
Mpls basicMpls basic
El bullying!
El bullying!El bullying!
El bullying!
Abel0700
 
Lectura,carte...încotro?
Lectura,carte...încotro?Lectura,carte...încotro?
Lectura,carte...încotro?
Lucretia Birz
 

Viewers also liked (10)

Question words (wh & how)
Question words (wh & how)Question words (wh & how)
Question words (wh & how)
 
Tecnologia educativa
Tecnologia educativaTecnologia educativa
Tecnologia educativa
 
resume_Malik Ross_IV Pharmacy Technician Hospital-Home Infusion 053115
resume_Malik Ross_IV  Pharmacy Technician Hospital-Home Infusion 053115resume_Malik Ross_IV  Pharmacy Technician Hospital-Home Infusion 053115
resume_Malik Ross_IV Pharmacy Technician Hospital-Home Infusion 053115
 
Deals2nitefinalpresentation
Deals2nitefinalpresentationDeals2nitefinalpresentation
Deals2nitefinalpresentation
 
Statement of purpose
Statement of purposeStatement of purpose
Statement of purpose
 
Sample SoP for MBA Application Sample
Sample SoP for MBA Application SampleSample SoP for MBA Application Sample
Sample SoP for MBA Application Sample
 
FPGA FIR filter implementation (Audio signal processing)
FPGA FIR filter implementation (Audio signal processing)FPGA FIR filter implementation (Audio signal processing)
FPGA FIR filter implementation (Audio signal processing)
 
Mpls basic
Mpls basicMpls basic
Mpls basic
 
El bullying!
El bullying!El bullying!
El bullying!
 
Lectura,carte...încotro?
Lectura,carte...încotro?Lectura,carte...încotro?
Lectura,carte...încotro?
 

Similar to VBA Tips

Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vbarjg_vijay
 
Learn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in DelhiLearn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in Delhi
ibinstitute0
 
VT University Live Session 3
VT University Live Session 3VT University Live Session 3
VT University Live Session 3
VisibleThread
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in India
ibinstitute0
 
Using macros in microsoft excel part 2
Using macros in microsoft excel   part 2Using macros in microsoft excel   part 2
Using macros in microsoft excel part 2
Er. Nawaraj Bhandari
 
Access tips access and sql part 6 dynamic reports
Access tips  access and sql part 6  dynamic reportsAccess tips  access and sql part 6  dynamic reports
Access tips access and sql part 6 dynamic reports
quest2900
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
guest38bf
 
Spreadsheet Analytical Tools
Spreadsheet Analytical ToolsSpreadsheet Analytical Tools
Spreadsheet Analytical Tools
Joselito Perez
 
Adding GetFormula to Your SpreadsheetsRachel Koh Spring 20.docx
Adding GetFormula to Your SpreadsheetsRachel Koh Spring 20.docxAdding GetFormula to Your SpreadsheetsRachel Koh Spring 20.docx
Adding GetFormula to Your SpreadsheetsRachel Koh Spring 20.docx
nettletondevon
 
Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1
rupeshkanu
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2
Dan D'Urso
 
An introduction to vba and macros
An introduction to vba and macrosAn introduction to vba and macros
An introduction to vba and macros
Er. Nawaraj Bhandari
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
JOSEPHINEA6
 
How To Automate Part 3
How To Automate Part 3How To Automate Part 3
How To Automate Part 3
Sean Durocher
 
003_AS1_Exercise_03_v1_0.pdf
003_AS1_Exercise_03_v1_0.pdf003_AS1_Exercise_03_v1_0.pdf
003_AS1_Exercise_03_v1_0.pdf
Khushal Chate
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeans
Huu Bang Le Phan
 

Similar to VBA Tips (20)

Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vba
 
Learn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in DelhiLearn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in Delhi
 
VT University Live Session 3
VT University Live Session 3VT University Live Session 3
VT University Live Session 3
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in India
 
Using macros in microsoft excel part 2
Using macros in microsoft excel   part 2Using macros in microsoft excel   part 2
Using macros in microsoft excel part 2
 
Access tips access and sql part 6 dynamic reports
Access tips  access and sql part 6  dynamic reportsAccess tips  access and sql part 6  dynamic reports
Access tips access and sql part 6 dynamic reports
 
Lab3 RTC Source Control
Lab3 RTC Source ControlLab3 RTC Source Control
Lab3 RTC Source Control
 
AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1AVB201.1 MS Access VBA Module 1
AVB201.1 MS Access VBA Module 1
 
VBA
VBAVBA
VBA
 
Spreadsheet Analytical Tools
Spreadsheet Analytical ToolsSpreadsheet Analytical Tools
Spreadsheet Analytical Tools
 
Adding GetFormula to Your SpreadsheetsRachel Koh Spring 20.docx
Adding GetFormula to Your SpreadsheetsRachel Koh Spring 20.docxAdding GetFormula to Your SpreadsheetsRachel Koh Spring 20.docx
Adding GetFormula to Your SpreadsheetsRachel Koh Spring 20.docx
 
Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2
 
An introduction to vba and macros
An introduction to vba and macrosAn introduction to vba and macros
An introduction to vba and macros
 
008.module
008.module008.module
008.module
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
How To Automate Part 3
How To Automate Part 3How To Automate Part 3
How To Automate Part 3
 
003_AS1_Exercise_03_v1_0.pdf
003_AS1_Exercise_03_v1_0.pdf003_AS1_Exercise_03_v1_0.pdf
003_AS1_Exercise_03_v1_0.pdf
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeans
 

Recently uploaded

State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

VBA Tips

  • 1. Bonus Chapter 2 TenVBATipsandTricks In This Chapter ᮣ Using helpful habits ᮣ Making your work more efficient This chapter contains a list of ten clever tricks I’ve developed (or acquired from other users) over the years. Getting VBA Help, Fast When working in a VBA module, you can get instant help regarding a VBA object, property, or method. Just move the cursor to the word that interests you and press F1. Speeding Up Your Macros If you write a VBA macro that produces lots of on-screen action, you can speed things up significantly by turning off screen updating. To do so, exe- cute this statement: Application.ScreenUpdating = False If your macro uses a custom dialog box, make sure to turn screen updating back on before displaying the UserForm. Otherwise, moving the dialog box on the screen leaves an ugly trail.
  • 2. 2 Excel VBA Programming For Dummies Avoiding Excel’s Questions Some VBA methods cause Excel to display a confirmation message, which requires the user to click a button. For example, the statement ActiveSheet.Delete always displays a dialog box that asks for confirmation. To eliminate such confirmation messages, execute the following before the statement that causes the confirmation messages. Application.DisplayAlerts = False Use this statement to reinstate the confirmation messages: Application.DisplayAlerts = True Displaying One Procedure at a Time Normally, a Code window in the Visual Basic Editor (VBE) shows all the pro- cedures in the module, one after another. If you find this distracting, set things up so that only one procedure is visible. 1. Activate the VBE and choose Tools➪Options. 2. Click the Editor tab in the Options dialog box. 3. Remove the check mark from the Default to Full Module View check box. Then you can use the drop-down lists at the top of the module window to select the procedure to view or edit. Using With-End With If you need to set a number of properties for an object, your code is easier to read and faster running if you use the With-End With construct. The following code doesn’t use With-End With: Selection.HorizontalAlignment = xlCenter Selection.VerticalAlignment = xlCenter Selection.WrapText = True Selection.Orientation = 0 Selection.ShrinkToFit = False Selection.MergeCells = False
  • 3. 3Bonus Chapter 2: Ten VBA Tips and Tricks The next code performs the same action but is rewritten to use With-End With: With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = True .Orientation = 0 .ShrinkToFit = False .MergeCells = False End With Reducing the Size of a Workbook In many cases, you can significantly reduce the size of a workbook — especially a workbook with modules you’ve heavily edited — because Excel does not do a good job of cleaning up after itself. To clean up the mess Excel leaves behind: 1. Save your workbook. 2. Select a module or a UserForm in the Project Window. 3. Right-click and choose Remove from the shortcut menu. 4. When asked whether you want to export the module, click Yes. 5. Repeat Steps 3 and 4 for each module and UserForm, keeping track of the modules and forms that you remove. 6. Choose File➪Import File to import all the modules and forms you deleted. 7. Save your workbook again. You usually find that the new workbook is much smaller than it was. Another way to reduce the size of a workbook file is as follows: 1. Activate your workbook. 2. Choose File➪Save As Web Page, and make sure that you use the Entire Workbook option. 3. Close your workbook. 4. Use File➪Open to open the HTML file that you saved in Step 2. 5. Use File➪Save As, and resave the workbook as a standard XLS file. In most cases, you’ll find that the file is smaller in size.
  • 4. 4 Excel VBA Programming For Dummies Bypassing a Workbook_Open Procedure Workbook_Open is a macro that Excel executes automatically when you open a workbook. In some situations, you may want to avoid running this macro. To do so, press the Shift key while opening the workbook. Using Your Personal Macro Workbook If you’ve developed some general-purpose macros, consider storing them in your Personal Macro Workbook, which opens automatically whenever Excel starts. When you record a macro, you have the option of recording it to your Personal Macro Workbook. The file, PERSONAL.XLS, is stored in your XLSTART directory. The Personal Macro Workbook is created the first time you record a macro to it. The Personal Macro Workbook is hidden by default. Displaying Messages in the Status Bar If you develop a lengthy macro, use the Excel status bar to display text that describes the progress of the macro. To do so, write some code that periodi- cally executes another macro, such as the following: Sub UpdateStatusBar(PctDone) Application.StatusBar = _ “Percent Completed: “ & Format(PctDone, “0%”) End Sub This procedure uses one argument: a value that ranges from 0 to 1.0. The macro simply displays a message that indicates the percent completed. To return the status bar back to normal, execute the following statement: Application.StatusBar = False Forcing Yourself to Declare All Variables Declaring every variable that you use in your code is an excellent practice. For example, if you use an integer variable named Count, declare it as Dim Count as Integer.
  • 5. Declaring your variables as a particular data type makes your code run faster and also helps avoid typographical errors. To force yourself to declare all variables, insert the following statement at the top of your module: Option Explicit If you would like this statement automatically added to each new module, follow these steps: 1. Activate the VBE and choose Tools➪Options. 2. In the Options dialog box, click the Editor tab. 3. Place a check mark next to Require Variable Declaration. 5Bonus Chapter 2: Ten VBA Tips and Tricks
  • 6. 6 Excel VBA Programming For Dummies