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.
- Skill level:
Other People Are Reading
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.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for