VBA Code Snippets

webimagevbacodesnippets

This page contains sections of common sections of code, which you can learn from, copy straight into your VBA projects, or just to remind you of the syntax.

Contents:

 

Application Settings

Control Custom Lists with VBA

Convert centimeters inches and pixels to points

Manipulating and changing scroll bars

 

Arrays

Sorting an array alphabetically with VBA

 

Cells and Ranges

Cell and Range VBA properties and actions

 

Files

Selecting a file using the File Dialog Box

Reading document properties

Find out if a file is already open by you or another user

Loop through all the files in a folder (and sub folders)

Copy, move, rename, delete and confirm existence of files

Zip and unzip files

Password protect an Excel file

 

Folders / Directories

Create, delete, rename and confirm existence of folders

Loop through all the files in a folder (and sub folders)

Zip and unzip folders

 

Loops

Loop through every worksheet or every workbook

Loop through all the files in a folder (and sub folders)

 

Named Ranges

Named Ranges – VBA properties & actions

 

PDF

Save Excel sheets, charts and workbooks as PDF

 

PowerPoint

PowerPoint VBA Reference Library

 

Security / Protection

Protect and unprotect worksheets

Protect and unprotect workbooks

Password protect an Excel file

 

Workbooks

Loop through every worksheet or every workbook

Workbook properties and actions

Protect and unprotect workbooks

Password protect an Excel file

Manipulating and changing scroll bars

 

Worksheets

Loop through every worksheet or every workbook

Protect and unprotect worksheets

 

Zip and Unzip files and folders

VBA code to Zip and unzipping files and folders

Save

Save

Save

Save