![]() |
|
#1
|
|||
|
|||
|
I have a Word 2016 document that upon opening, I want an ActiveX Text Box to update with a random quote. When I run the code via Debug, it works perfectly 100% of the time, however when I open the document, it seems to always display the same quote (i.e. Quote 11) and I can't seem to figure out where I've gone wrong? This is my code within a standard Module:
Code:
Sub AutoOpen()
Dim MyDocName As String
Dim strQuotes(15) As String
Dim lngIndex As Long
MyDocName = Application.ActiveDocument.Name
strQuotes(0) = "'Quote 1'"
strQuotes(1) = "'Quote 2'"
strQuotes(2) = "'Quote 3'"
strQuotes(3) = "'Quote 4'"
strQuotes(4) = "'Quote 5'"
strQuotes(5) = "'Quote 6'"
strQuotes(6) = "'Quote 7'"
strQuotes(7) = "'Quote 8'"
strQuotes(8) = "'Quote 9'"
strQuotes(9) = "'Quote 10'"
strQuotes(10) = "'Quote 11'"
strQuotes(11) = "'Quote 12'"
strQuotes(12) = "'Quote 13'"
strQuotes(13) = "'Quote 14'"
strQuotes(14) = "'Quote 15'"
strQuotes(15) = "'Quote 16'"
lngIndex = Int((15 - 0 + 1) * Rnd + 0)
Documents(MyDocName).tbRandomQuote.Value = strQuotes(lngIndex)
End Sub
I'm sure it'll be so simple, but I've pulled my hair out going around in circles. Thanks so much for any assistance / guidance you could offer. Corin. |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Auto-update field codes in Outlook Template - AutoOpen Macro not working | victoriasun | Outlook | 5 | 12-22-2015 01:54 AM |
| Update a summary chart when I update a dashboard with dates | cangelis | Excel | 6 | 09-24-2014 08:08 AM |
Display result in textbox based on the input of another textbox
|
scarymovie | Word VBA | 5 | 05-16-2012 07:05 PM |
| Textbox Template | t0m46 | Word | 0 | 09-07-2010 03:38 AM |
Making a Macro "autoopen"
|
Joshocom | Word | 1 | 03-16-2010 05:03 PM |