Wrox Programmer Forums
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2007, 07:39 AM
Registered User
 
Join Date: Oct 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Word Parsing - VB.net

Hello again,

I am wanting to read a certain style of heading from a Word document, once I find it I want to export it into a CSV file, or XML document.

When I am running the programme and I check the output file theres nothing in it can anybody help?

Below is the code which I am using.

Imports System.IO
Imports Word
Imports WordAutomation

Public Class Form1
    Public wdoc As Word.Document
    Public wapp As Word.Application

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Declarations
        Dim doc As New Word.Document
        Dim wordApp As New Word.Application
        Dim arguments As [String]() = Environment.GetCommandLineArgs()
        Dim fsStream As New FileStream("a:\test.csv", FileMode.Append, FileAccess.Write)
        Dim swWriter As New StreamWriter(fsStream)

        doc = wordApp.Documents.Open("c:\temp\MCG1115A15")
        wordApp.Visible = True
        wordApp.Selection.EndKey(Word.WdUnits.wdStory)
        wordApp.Selection.HomeKey(Word.WdUnits.wdStory, Word.WdKey.wdKeyShift)

        'Variables
        Dim count As Integer
        count = wordApp.Selection.Range.ComputeStatistics(Word.WdS tatistic.wdStatisticLines)

        'Variables
        Dim i As Integer

        For i = 0 To 2
            wordApp.Selection.HomeKey(Word.WdUnits.wdLine)

            If wordApp.Selection.Range.Style.ToString = "Test Heading 2" Then
                swWriter.Write("Test Heading 2", wordApp.Selection.Range.Style.ToString)
                swWriter.Close()
            End If
            wordApp.Selection.MoveDown(Word.WdUnits.wdLine, 1)
        Next
    End Sub
End Class







Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.Net Word Automation deboe Pro Visual Basic 2005 0 November 26th, 2007 09:57 PM
formatting of a word document with vb.net krmilburn General .NET 0 April 18th, 2006 06:47 AM
Reading MS WORD Document by VB.Net ocarroll General .NET 0 March 31st, 2006 02:17 AM
VBA Word is very slow with vb.net preeti01 VB How-To 4 May 5th, 2005 05:01 AM
Word to HTML Converter in VB.NET? Ron Howerton VB.NET 2002/2003 Basics 0 February 18th, 2004 03:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.