Word Macros and VBA – InputBox

InputBox in VBA prompts users to enter values in the input field. Let us see an example Macros & VBA in Word that uses InputBox and does the following

InputBox Macros and VBA in Word

  • Creates a blank new word document.
  • Prompts users with the InputBox and the entered text will be used as the title for the document.
  • Coverts the title to upper case.
  • Change the title’s font style
  • Align the title text to centre of the document
  • Leaves out two empty lines after the title.
  • Reverts fonts style and alignment of the document to left.

Public Sub insertTitle()

'Create a blank document.

Documents.Add DocumentType:=wdNewBlankDocument

'Store text entered in InputBox in a variable.

Dim strTitle As String

strTitle = InputBox("Enter title for the document", “Title")

'Insert the title (input text) after converting to upper case.

Selection.TypeText UCase(strTitle)


'Change the title font style

With Selection

.Font.Bold = True

.Font.Size = "20"

End With

'Align the title text to center.

Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

'Leave out one space after the title.

Selection.MoveRight Unit:=wdCharacter, Count:=1

'Enter two blank lines.



'Change the alignment back to left

Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft

'Revert the font style to paragraph style.

With Selection

.Font.Bold = False

.Font.Size = "12"

End With

End Sub

Enter title for document using Macros and VBA

In Category: Apple, Mac, Word 2007, Word 2010, Word 2013

Ravi Shankar

A Software developer and blogger who is always looking to provide technical help to the wider community.

Show 0 Comments
No comments yet. Be the first.

Leave a Comment

Get your free copies of the following tech guides by joining the Digital Answers mailing list.