Excel and VBA

Up Earthquakes Excel and VBA Finite Elements

(more stuff can be found throughout my classes web pages since I use these sorts of spreadsheets all the time)

Introduction

Before doing anything with VBA in Excel, you should first get comfortable with Excel. The following tutorial is an example of using Excel to study the load deformation behavior of a simple beam. It's intended to illustrate the usefulness of Excel, not my structural analysis prowess.

Using spreadsheets for Parametric analyses

This is the companion spreadsheet that I used in the assignment

Beamdeflectionv.xls  Right-click and save-as

 

If you are unfamiliar with using Visual Basic in Excel, take a look a the little tutorial below. It shows how to construct a Visual Basic Function that the user can call from Excel as a User Defined Function. It's a good starting point

Functions in Excel

This is a function call in that it returns a value when used (like say, cosine(1.23) does). Many routines don't need to return values, but do operate on numbers passed in and out of the routine. In Visual Basic, these are Subs (short for subroutines)

Writing Loops in Basic

If you have done any programming at all, you will know the power of writing loops or iterations. They allow you to write out matrix data, perform matrix operations, calculate integrals, compute time-dependent behavior, ... the list is endless. Here is a simple starting point for you. Note the worksheet marked "Instructions" that may be a good place to begin

VBAloop.xls : Right-click and "Save Target As" on your machine. If you have really high security on your system, you will not be able to open or run the macros immediately. If that happens, click Tools>Macro>Security and set the security level to medium, then Save and Close the spreadsheet. Open the spreadsheet again and you should get a message box saying that Macros may have viruses etc, etc.., click on Enable Macros so that you can use them. You can edit the code in Visual Basic to anything you want...you may want to make a copy first before making any changes to something that works!

 

 

Goofy User Forms

I wrote a little user form demo spreadsheet just to show you how to get started. Usually you want the forms to do something, but that never stopped any of those Visual Basic Book Authors from writing totally useless routines. The main thing to garner from this example is to compare the Code with the Form (they always go together) Play with the code segment so that you can do something when you click a button. It takes a little practice, but you got all day....right??

VBA userform demo.xls : Right-click and "Save Target As"....problems getting it to run ? See discussion under VBAloop.xls.