[英]Excel Userform TextBox.Value Populate MS Word Bookmarks
Private Sub CommandButton3_Click()
Dim wApp As Object
Dim wDoc As Object
Set wApp = CreateObject("Word.Application")
wApp.Visible = True
Set wDoc = wApp.Documents.Open(Filename:="C:\template1.dotm ", ReadOnly:=False)
With wDoc.Selection
.Bookmarks("bookmark1") = UserForm5.TextBox1.Value
.Bookmarks("bookmark2") = UserForm5.TextBox2.Value
End With
WordDoc.Close
WordApp.Quit
Set WordDoc = Nothing
Set WordApp = Nothing
End Sub
Hello All, 大家好,
I was hoping that someone could help me on this one. 我希望有人可以帮助我解决这一问题。 As shown on the code above, I am trying to get the userform textbox value and populate it to MS Word using bookmarks.
如上面的代码所示,我试图获取userform文本框值,并使用书签将其填充到MS Word中。
The issue is that when I click command button 3 on the userform, the MS word opens but the bookmarks is still empty ie no value 问题是,当我单击用户窗体上的命令按钮3时,MS字会打开,但书签仍为空,即没有值
I would appreciate the help as I have been trying to resolve this for hours. 感谢您的帮助,因为我已经尝试解决了数小时。 Many thanks.
非常感谢。
Regards, Kevin 问候,凯文
The bookmark commands need a Range and Text properties. 书签命令需要Range和Text属性。 Example
例
.Bookmarks("bookmark1").Range.Text = UserForm5.TextBox1.Value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.