2016-11-28 72 views
1

我想通過即時編輯在Visual Studio 2010程序,但即時通訊有麻煩,可以編輯現有的MS Word文檔的程序。我的代碼:編輯通過視覺工作室一個msword文件

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 

錯誤說:「財產範圍只讀」

回答

0

你的代碼幾乎是正確的。如果要查看Range對象的文本,則需要使用其.Text屬性:

With wd1Doc 
    .FormFields("w_name").Range.Text = TextBox1.Text 
    .FormFields("w_age").Range.Text = TextBox2.Text 
End With