Ron
Ron

Reputation: 1

Inserting InputBox information into Word Document

Hi I am new to VBA and I am trying to insert InputBox text into a word document. In this case just printing the asked first and last name via the InputBox into the document. I need to base the sub procedure from the line:

strFull = strFirstName & " " & strLastName

My current sub procedure just ends up printing "strFull" in a new word document instead of the InputBox First and Last name. What am i doing wrong? My code is below:

Public Sub Insert_Name_Into_Word()
'Set wd as the object variable for Word and store the address as Word.Application'
Dim wd As Word.Application
'Set doc as the object variable and store the address as Word.Document'
Dim doc As Word.Document
'Set para as the object variable and store the address as Word.Pargraph'
Dim para As Word.Paragraph
'Set strFirstName as the object variable for a string, Same for strLastName, and for strFull as well'
Dim strFirst As String, strLast As String, strFull As String

'Set the address of wd create a new word application'
Set wd = New Word.Application
'Set the address of doc to create a new document in a new word application window'
Set doc = wd.Documents.Add
'Make the new Word Application visible'
wd.Visible = True

'make stored variable an input box response for entering name'
strFirst = InputBox(prompt:="Enter Your Name:", Title:="FirstName")
'declare last name in input box'
strLast = InputBox(prompt:="Enter Your Last Name:", Title:="Last Name")
'Identify strFull as strFirst plus strLast'
strFull = strFirstName & " " & strLastName
'make the address of para a creation of a new paragraph in doc'
Set para = doc.Paragraphs.Add
'make para's text to InputBox outputs'
para.Range.Text = "strFull"


End Sub

Upvotes: 0

Views: 335

Answers (1)

macropod
macropod

Reputation: 13490

Use:

para.Range.Text = strFull

not:

para.Range.Text = "strFull"

Upvotes: 1

Related Questions