-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: true-developer
Message 1 in Discussion
Hi all I am developing an application in ASP.net and VB.net. I am trying to use mail
merge facility of MS-word. I am getting following exception on the line, with the red
color in the code below. An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in microsoft.visualbasic.dll
Additional information: 'Range' is not a by reference property.
Dim WordApp As Object = New Word.ApplicationClass
WordApp.WindowState = Word.WdWindowState.wdWindowStateNormal
WordApp.ChangeFileOpenDirectory("C:\Inetpub\wwwroot\MSWordTest\test\")
WordApp.Documents.Open(FileName:="t2.doc", ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate _
:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="" _
, Format:=Word.WdOpenFormat.wdOpenFormatAuto)
WordApp.Selection.Find.ClearFormatting()
With WordApp.Selection.Find
.Text = "\<\<*\>\>"
.Replacement.Text = "<F1>"
.Forward = True
.Wrap = Word.WdFindWrap.wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
WordApp.ActiveDocument.MailMerge.OpenDataSource(Name:= _
"C:\Inetpub\wwwroot\MSWordTest\test\RS1.txt", ConfirmConversions:=False, ReadOnly:= _
False, LinkToSource:=True, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", WritePasswordDocument:="", WritePasswordTemplate:= _
"", Revert:=False, Format:=Word.WdOpenFormat.wdOpenFormatAuto, Connection:="",
SQLStatement _
:="", SQLStatement1:="", SubType:=Word.WdMergeSubType.wdMergeSubTypeOther)
Dim i As Integer
i = 0
Dim strFindText As String
While WordApp.Selection.Find.Execute = True
i = i + 1
strFindText = strFindText & WordApp.Selection.Text & " : "
Dim field As String
field = "F" & i
Dim range As Word.Range = WordApp.Selection.Range
'WordApp.Selection.Find.Replacement.Text =
'WordApp.ActiveDocument.Fields.Add(range:=range,
Type:=Word.WdFieldType.wdFieldMergeField, Text:="Field...")
End While
WordApp.ActiveDocument.Fields.Add(WordApp.Selection.Range,
Word.WdFieldType.wdFieldMergeField _
, """F1""")
WordApp.ActiveDocument.Fields.Add(range:=WordApp.Selection.Range,
Type:=Word.WdFieldType.wdFieldMergeField _
, Text:="""F2""")
WordApp.ActiveDocument.Save()
WordApp.ActiveDocument.Close()
WordApp.Quit()
Dim AllProcess() As Process = Process.GetProcessesByName("WINWORD")
Dim WordProcess As New Process
For Each WordProcess In AllProcess
WordProcess.Kill()
Next
WordProcess.Close()
Me.Label1.Text = strFindText & "Fiels have been mail merged......"
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]