在 ms word 文件中通过 visual studio 编辑
edit through visual studio an msword file
我正在尝试一个程序,该程序可以通过 visual studio 2010 程序中的即时编辑来编辑现有的 ms word 文档,但我遇到了麻烦。我的代码:
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim wd1 As Word.Application
Dim wd1Doc As Word.Document
wd1 = New Word.Application
wd1.Visible = True
wd1Doc = wd1.Documents.Add("C:\Users\DELL\Desktop\activity6\profile.dotx")
With wd1Doc
.FormFields("w_name").Range = TextBox1.Text
.FormFields("w_age").Range = TextBox2.Text
End With
wd1 = Nothing
wd1Doc = Nothing
End Sub
End Class
错误说:"property range is read only"
您的代码几乎是正确的。如果你想要 Range
对象的文本,你需要使用它的 .Text
属性:
With wd1Doc
.FormFields("w_name").Range.Text = TextBox1.Text
.FormFields("w_age").Range.Text = TextBox2.Text
End With
我正在尝试一个程序,该程序可以通过 visual studio 2010 程序中的即时编辑来编辑现有的 ms word 文档,但我遇到了麻烦。我的代码:
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim wd1 As Word.Application
Dim wd1Doc As Word.Document
wd1 = New Word.Application
wd1.Visible = True
wd1Doc = wd1.Documents.Add("C:\Users\DELL\Desktop\activity6\profile.dotx")
With wd1Doc
.FormFields("w_name").Range = TextBox1.Text
.FormFields("w_age").Range = TextBox2.Text
End With
wd1 = Nothing
wd1Doc = Nothing
End Sub
End Class
错误说:"property range is read only"
您的代码几乎是正确的。如果你想要 Range
对象的文本,你需要使用它的 .Text
属性:
With wd1Doc
.FormFields("w_name").Range.Text = TextBox1.Text
.FormFields("w_age").Range.Text = TextBox2.Text
End With