Hello to all...
I wana ask you if you think that's the best and the fastest way to replace <<words>> into a .doc file?
I don't know other way and i think mine is too slow for doing this kind of job.
I'm waiting your opinions and... Thanks in advice...Code:Dim word As New Microsoft.Office.Interop.Word.Application Dim doc As Microsoft.Office.Interop.Word.Document Try doc = word.Documents.Open(System.Windows.Forms.Application.StartupPath & "\cdmf.mbm") doc.Activate() Dim myStoryRange As Microsoft.Office.Interop.Word.Range For Each myStoryRange In doc.StoryRanges With myStoryRange.Find .Text = "<<filiala>>" .Replacement.Text = Me.txt_filiala.Text .Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll) End With With myStoryRange.Find .Text = "<<data>>" .Replacement.Text = Me.txt_data_cm.Text .Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll) End With With myStoryRange.Find .Text = "<<seriacm>>" .Replacement.Text = Me.txt_seria_cm.Text .Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll) End With With myStoryRange.Find .Text = "<<nrcm>>" .Replacement.Text = Me.txt_nr_cm.Text .Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll) End With With myStoryRange.Find .Text = "<<numeprenume>>" .Replacement.Text = Me.txt_nume_prenume.Text .Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue .Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll) End With Next myStoryRange doc.SaveAs(System.Windows.Forms.Application.StartupPath & "\cdm\" & "\" & Me.txt_cnp.Text & "\" & Me.txt_nr_cm.Text & ".mbm") doc.Close() doc = Nothing Catch ex As Exception MessageBox.Show("Error opening.") End Try




Reply With Quote