Excel and Visual Basic Applications

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

Freeform Problem

Here is the discussion of the VBA freeform problem I discussed in the forum

Freeform Problem

Beam Deflection

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 html  pdf

This is the companion spreadsheet that I used in the assignment

Beamdeflectionvalues.xls  Right-click and save-as

This is the spreadsheet we will use in class

BeamDeflectionExercise.xlsm 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)

More Introductory Information

If you would like more information on using Excel and VBA, try the link that will lead to an instructionalwebpage, or download the PDF files listed below.

Here is the link: Link to Tutorial

Here are the PDF files

Introduction 1     Introduction 2    Introduction 3

Intro To VBA 1   Intro To VBA 2   Intro To VBA 3

Passing Parameters      Speed Barrier

 

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 you are using Office 2007 (like we have in the lab)

Opening Permission For Macros in Excel 2007

  1. Go to the MSOffice logo and click on it.
  2. Click on Excel Options
  3. Click on Trust Center
  4. Click on Macro Security
  5. Allow Macros (ignore the warning)
  6. Close the spreadsheet and re-open it.

Check here for a little video how to do it. MacroEnable.swf

If you are using Office 2003 (or older), open a spreadsheet, 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.

Matrix Multiply Spreadsheet

Listed below is the matrix multiply spreadsheet we worked on in class, give it a try.

Matrix work spreadsheet

Truss Problem Spreadsheet

Download this bad boy for work on Friday....try it out a little.

Truss Spreadsheet 2009

Some Trusses for your viewing pleasure (courtesy US Military Academy)

http://www.eecs.usma.edu/bridgecontest/pdfs/appendb.pdf