将InputBox信息插入Word文档



嗨,我是VBA新手,正在尝试将InputBox文本插入word文档中。在这种情况下,只需通过InputBox将询问的名字和姓氏打印到文档中。我需要根据以下行的子过程:

strFull = strFirstName & " " & strLastName

我当前的子过程只是以打印";strFull"在一个新词文档中,而不是InputBox的名字和姓氏。我做错了什么?我的代码如下:

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

使用:

para.Range.Text = strFull

不是:

para.Range.Text = "strFull"

最新更新