|

How to Copy Text to and from the Clipboard in Excel and Access Visual Basic

You can record a macro to copy from and paste to the Excel worksheet.  Easy enough.  But what if you have a value in Microsoft Excel VBA that you want to put on the clipboard for another program?  Or you want your code to get text from the clipboard after you copied it there from…

|

How to Pass Arguments Efficiently in Visual Basic

This is from Microsoft Excel 2000 Visual Basic Help, with changes and additions. All arguments are passed to procedures by reference, unless you specify otherwise. This is efficient because all arguments passed by reference take the same amount of time to pass and the same amount of space (4 bytes) within a procedure regardless of…

|

How to Write a Visual Basic Function Procedure

This is from Microsoft Excel 2000 Visual Basic Help, with changes and additions. A Function procedure is a series of Visual Basic statements enclosed by the Function and End Function statements. A Function procedure is like a Sub procedure, but a function can also return a value. A Function procedure can take arguments, such as…

|

How to Understand Visual Basic Syntax

This is an excerpt from Microsoft Excel Visual Basic Help, with extra Notes. The syntax in a Visual Basic Help topic for a method, statement, or function shows all the elements needed to use the method, statement, or function. The examples in this topic explain how to interpret the most common syntax elements. 1.        Activate…

|

Visual Basic Naming Rules and Tips

This is an excerpt from Microsoft Excel Visual Basic Help, with tips and corrections. Use these rules when you name procedures, constants, variables, and arguments in Visual Basic: 1.        Capitalization and Case-Sensitivity Visual Basic isn’t case-sensitive, but it preserves the capitalization in the statement where the name is declared. If you declare variables with the…

|

How to Use Objects, Properties, Methods, and Events in Visual Basic

This is an excerpt from Microsoft Excel 2000 Visual Basic Help. 1.        Objects and Collections An object represents an element of an application, such as a worksheet, a cell, a chart, a form, or a report.  In Visual Basic code, you must first identify an object.  Only then can you apply one of the object’s…

|

How to Iterate for a Solution with an Excel Macro: The Manning Formula for Open-Channel Flow

The Manning formula for open-channel flow is:   whereV= Velocityn = Manning’s “n”,r = Hydraulic radius = area / wetted perimeter = b*y / (2*y + b) for a rectangular channel (where y = depth and b = width), ands = slope of channel (m/m).  Discharge Q = V*A = V*b*y.  We cannot solve this…

|

How to Store Program Settings in the Registry from Excel Visual Basic

Windows stores program settings in the Registry, a Windows internal database.  You can use this to remember previous user choices and use them as defaults the next time.  We typically remember window positions, file paths, and other settings with the Registry. These three commands work with items stored in the Registry: SaveSetting appname, section, key,…

|

Useful Keywords to Know in Excel Visual Basic

1.        The Application Keyword Use “Application” to refer to Excel, e.g.: Application.ActivePrinter Name of the Active Printer.Application.Name            Name of the program running (“Microsoft Excel”).Application.Path            The path from which the program is running. 2.        ActiveControl Instead of the name of a specific control (e.g. txtEdit), you can use the keyword ActiveControl.  This will let your program refer…

|

A List of the Excel Visual Basic Editor Shortcut Keys

While you can pick these Shortcut Keys up from the menus in the Excel Visual Basic Editor, it is useful to have them all in one place. F1                         Help on the highlighted itemF2                         Object BrowserShift+F2               View Definition (Go to highlighted Sub or Function)F3                         Repeat last FindF4                         Display Properties WindowF5                         Run / Continue RunF8                         Single Step…