Results 1 to 3 of 3

Thread: [2008] Replacing. Is this the best way ?

Threaded View

  1. #1

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    [2008] Replacing. Is this the best way ?

    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.

    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
    I'm waiting your opinions and... Thanks in advice...
    Last edited by Alexandru_mbm; Jan 14th, 2009 at 04:20 PM.
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width