Inserting large text into word document using Find Replace

T

Tim

Hello All,

I have attempted to use the .Content.Find.Execute() function while setting
the replacewith: parameter to a variable.

The code works however since the parameter is a string with a size
limitation I run into issues when the retrieved value is extremely large.

I was wondering if anyone has used this functionality to some how set the
cursor poistion in Word and then insert a value from a dataset directly into
a word document?

Any help would be appreciated.

Thanks!
 
T

Tim

I should add this code is being developed in vb.net for a stand alone windows
application.
 
T

Tim

The following code worked for moving the replacing the token, moving the
cursor and using a dataset.table value for inserting the text as opposed to
attempting to assign the value to a string

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim app As New Microsoft.Office.Interop.Word.Application
Dim doc As Microsoft.Office.Interop.Word.Document =
app.Documents.Add("test7")
Dim para1 As Microsoft.Office.Interop.Word.Paragraph
Dim docString As String
Dim count As Integer
Dim test As Boolean

cmdcommand.Connection = GetConnection()
cmdcommand.CommandText = "SELECT
field_eis_purpose_value,field_eis_agenda_value,field_eis_notes_value,field_eis_requirements_value," & _

"field_eis_action_items_value,field_eis_open_issues_value,field_eis_meeting_date_value,field_eis_attendees_value " & _
"FROM content_type_eis_meeting_notes meeting " & _
"INNER JOIN (select max(vid) as vid from
content_type_eis_meeting_notes group by nid) m2 ON " & _
"m2.vid = meeting.vid LEFT OUTER JOIN content_field_eis_notes note
on " & _
"note.vid = meeting.vid LEFT OUTER JOIN
content_field_eis_open_issues issue ON " & _
"note.vid = issue.vid WHERE meeting.nid = 681"

daDataAdapter.SelectCommand = cmdcommand
'Populate temp dataset
daDataAdapter.Fill(dsDataSetFinal)

count = 0
test = True

Do While test
ReplaceText(app, count)
app.Selection.Text = dsDataSetFinal.Tables(0).Rows(0)(count)
count += 1
test = doc.Content.Find.Execute(findtext:="{Text}")
Loop
doc.SaveAs("Test123")
app.Visible = True
End Sub
Public Function ReplaceText(ByRef app As
Microsoft.Office.Interop.Word.Application, ByVal i As Integer)

With app.Selection.Find
.Execute(findtext:="{Text}", _
ReplaceWith:="")
.Forward = True
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
End With
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top