In today’s post, we want to explain the way to add a “Quote of the Day” feature in your Word to learn new quote every day.
The feature “Quote of the Day” shows one different quote each time you start Word. Just take seconds to read a quote of wisdom before you burying yourself in tons of work. This shall do you much good.
Therefore, follow our leads to add such a feature in your Word now.
Put Quotes in an Excel File
- First of all, open Excel and rename a new sheet as “Quotes”.
- Next input “Number” in cell A1, “Quotes” in cell B1, and “Times” in cell C1.
- Then fill column A with serial numbers.
- Add one quote in each cell in column B.
- And input number “0” in column C.
- Lastly, name the Excel file as “Quote of the Day”. And save it in a folder. In our case, after we saved the file, its full address shall look like as below:
C:\Users\Public\Documents\Sample\Quote of the Day.xlsx
Accordingly, you should remember yours.
You can click here to download a sample file.
Insert a Module in VBA Project
- To begin with, trigger VBA editor in Word by pressing “Alt+ F11”.
- On the “Project” panel on the left, click “Normal”.
- Then click “Insert” tab on the menu bar.
- And choose “Module” on the drop-down menu.
- Next double click to open the new module.
- Now paste following codes there:
Sub AutoExec() Dim objExcel As Excel.Application Dim objWorkbook As Excel.Workbook Dim objWorksheet As Excel.Worksheet Dim nRowIndex As Integer Dim nMinValue As Integer Dim nMinRowIndex As Integer Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("C:\Users\Public\Documents\Sample\Quote of the Day.xlsx") Set objWorksheet = objWorkbook.Sheets("Quotes") ' Initialization nMinValue = 0 nMinRowIndex = -1 For nRowIndex = 2 To objWorksheet.UsedRange.Rows.Count If (nMinRowIndex = -1) Then nMinValue = objWorksheet.Cells(nRowIndex, 3).Value nMinRowIndex = nRowIndex Else If (objWorksheet.Cells(nRowIndex, 3).Value < nMinValue) Then nMinValue = objWorksheet.Cells(nRowIndex, 3).Value nMinRowIndex = nRowIndex End If End If Next nRowIndex frmQuoteOfTheDay.txtQuoteOfTheDay.text = objWorksheet.Cells(nMinRowIndex, 2).Value frmQuoteOfTheDay.Show Modal objWorksheet.Cells(nMinRowIndex, 3).Value = objWorksheet.Cells(nMinRowIndex, 3).Value + 1 objWorkbook.Close SaveChanges:=True ' Close Excel using Quit method on the Application object. objExcel.Application.Quit ' Release the object variable. Set objExcel = Nothing End Sub
- Click “Save” button.
Note:
In this code line:
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\Public\Documents\Sample\Quote of the Day.xlsx")
Remember to replace the path address with an actual one.
Insert a User Form
Next we will create a user form to show the quote.
- Still, in VBA editor, click “Insert” tab again.
- Only this time, you choose “UserForm”.
- Then you will have a user form. Click on the form handles to resize it.
- Next press “F4” to open “Properties” window. It will appear on the left-down corner of the screen.
- Name the form as “frmQuoteOfTheDay” and set its caption as “Quote of the Day”. Besides, set font and background color properly. And choose “False” for the “ShowModal”.
- Then click “Toolbox” command on menu bar to bring out the box.
- Use the controls to create a text box, a label, and a command button. Arrange them in following order:
- Next you ought to set properties for these controls.
- First, click on label. Set the caption text as “Quote of the Day”. Apply proper font size and set the background as transparent.
- Second, click on text box. Name it as “txtQuoteOfTheDay”.
- Third, click on command button. Name it as “btnClose” and set caption as “Close”. Then double click on the “Close” button to open coding area. Enter following codes:
Private Sub btnClose_Click() Unload Me End Sub
- Finally, save codes.
Each time you start Word, you will see a user form such as below:
Fix Word Problems
It’s inevitably to encounter with this or that issue in Word which might lead to a corrupted document. The most important thing is to handle each crisis quickly and properly. This, however, will require a professional tool to recover docx.
Author Introduction:
Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including damaged Excel and pdf repair software products. For more information visit www.datanumen.com
1