The Microsoft Office Word text processing program includes the Visual Basic for Applications scripting tool that allows users to insert calculated fields, such as a Fibonacci sequence of numbers, in their text documents. The Fibonacci numbers are the integer sequence 0, 1, 1, 2, 3, 5, 8, 13, 21, ..., in which each item is the sum of the previous two numbers in the sequence. By implementing a recursive loop in your VBA script, you can calculate a Fibonacci sequence in VBA Word.
Click the "Start" button in Windows and select the "Microsoft Word" program.
Click "Tools" and then "Scripts" to create the VBA script for calculating a Fibonacci sequence.
Enter the following code in the window:
Function fibonacci(ByVal n as Integer)
If (n <= 0) Then
fibonacci = 0
ElseIf (n = 1) Then
fibonacci = 1
fibonacci = fibonacci(n-1) + fibonacci(n-2)
Click "File" and then "Save" to save the "fib.doc" Word document with the VBA script for calculating Fibonacci sequence of numbers.
- Photo Credit Jupiterimages/Photos.com/Getty Images
How to Create Sequences in Excel
One of the features of spreadsheet programs like Microsoft Excel is that they can save a great deal of repetitive typing. If...
How to Calculate Fibonacci Retracements
Thirteenth-century mathematician Fibonacci of Pisa, in trying to find the solution to a math problem about rabbits, stumbled onto a sequence of...
How to Calculate Averages in VBA
VBA (Visual Basic for Applications) includes the ability to write instructions creating a macro that will mimic using a calculator to enter...
How to Calculate Fib. Projections
Investment analysts sometimes use Fib projections, or Fibonacci projections, to estimate where a current move in a financial instrument's price might end....
How to Insert Text Into a Word Document in VBA
Microsoft Word is a word processing application that is part of the Office suite. VBA is commonly used to automate routine tasks...
How to Calculate 8-Bit Sequence
Bits are the most fundamental building blocks of computer software. A bit can be either 1 or 0, on or off. Eight...
How to Calculate the Sum of 3 Numbers in Visual Basic
Calculating the sum of three numbers can easily be accomplished using a Windows Forms Project in Visual Basic. The best thing to...
How Do I Close a Word Document With VBA?
Visual Basic for Applications (VBA) is a specific programming language that is used primarily to control certain functions in Excel, but it...