Go line by line through a Microsoft Word document with vb.net

Good Morning! Well I think I like the new design of Windows Live! I am still getting used to it but it is an extremely intriguing look! Had some connection issues yesterday and this morning but I am assuming these are just early bugs.

Yesterday I had to come up with a way to modify a lot of Microsoft Word documents and make small changes through each. Instead of having to do it manually, I wanted to automate it. So is here is what I came up with! Make it a great day!

Private  Sub test(ByVal docfile As String)
            Dim missingvalue As Object =  System.Reflection.Missing.Value
            Dim app As Microsoft.Office.Interop.Word.Application =  New Microsoft.Office.Interop.Word.Application()
            Dim doc As Microsoft.Office.Interop.Word.Document =  app.Documents.Open( docfile,ref missingvalue,ref missingvalue,ref missingvalue,ref missingvalue,ref missingvalue,ref missingvalue,ref missingvalue,ref missingvalue,ref missingvalue,ref missingvalue,ref missingvalue)
            Dim totallines As Integer =  doc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticLines)
            Dim i As Integer
            For  i = 1 To  totallines Step  i + 1
                app.Selection.GoTo(Microsoft.Office.Interop.Word.WdGoToItem.wdGoToLine, Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToAbsolute, i, missingvluae)
                app.Selection.TypeText("Replacement text for line " + i.ToString())
            Next
           ‘code to save/close your code
End Sub

Technorati Tags: ,,,,,,,,,,,,,,,,,,,,,

Windows Live Tags: vb.net,.NET Framework,csharp,Windows,line,Microsoft,Word,Live,documents,System,Reflection,Office,Interop,Application,Document,ComputeStatistics,WdStatistic,Selection,WdGoToItem,WdGoToDirection,TypeText,Replacement

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: