borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Help Me................i\'t urgent2)Next Topic (converting Column number to letters) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Help me.....it's urgent
Poster Message
sunoff
Level: Scholar

Registered: 17-12-2004
Posts: 47

icon Help me.....it's urgent

how to get section number/index at specified range in word doc using vb/.net?
for example i have range of words and this range of words is in section /page 1.how to get index of this section/page that is page is page 1.

EXAMPLE:
RANGE(0,5) is HELLO and on page 1
Range(100,105) is WORLD and on page 2
how to get page/section number like hello is in page 1 and world is in page 2?

i have some code example,but it's result was false.


wrdDoc = New Word.Document
        wrdApp = New Word.Application

        Try
            wrdApp.Visible = True
            wrdDoc = wrdApp.Documents.Open("C:\Documents and Settings\TA\My Documents\coba4.doc")
            wrdDoc.Activate()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        Finally
            'wrdDoc.Close()
        End Try

        wrdDoc.Repaginate()
        Dim NumSections As Integer
        NumSections = wrdDoc.Sections.Count

        Dim rng As Word.Range
        Dim rng2 As Word.Range
        Dim rng3 As Word.Range

        Dim kata() As String
        Dim start, ends As Object
        start = wrdDoc.Content.Start
        ends = wrdDoc.Content.End
        Dim n As Integer
        Dim leftmrg, rightmrg, bottommrg, topmrg As Single
        Dim pheight, pwidth As Double
        Dim orientasi As Word.WdOrientation

        pheight = wrdDoc.PageSetup.PageHeight
        pwidth = wrdDoc.PageSetup.PageWidth
        leftmrg = wrdDoc.PageSetup.LeftMargin
        rightmrg = wrdDoc.PageSetup.RightMargin
        bottommrg = wrdDoc.PageSetup.BottomMargin
        topmrg = wrdDoc.PageSetup.TopMargin
        Dim h, j, k, t, p, kt As Integer
        Dim align As String
        j = 0
        h = 0
        t = 0
        kt = 0
        p = 1

        
        For k = 0 To ends

            If k = ends Then
                rng = wrdDoc.Range(j - 1, ends)
            Else
                rng = wrdDoc.Range(j, k + 1)
            End If


            '-------HOW TO GET SECTION INDEX??--------------
            If rng.Sections.First.Index <> n Then
                messagebox.show(rng.Sections.First.Index)
            End If
            '----------------------------------------------------------


            If rng.Text = " " Then
                rng2 = wrdDoc.Range(h, k)
                h = k + 1
                j = j + 1
                
            ElseIf rng.Text = "." Then
                rng3 = wrdDoc.Range(t, k)
                kata(kt) = rng3.Text
                j = j + 1
                kt = kt + 1

            Else
                j = k + 1
            End If
        Next If rng.Sections.First.Index <> n Then

16-10-2005 at 05:12 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : Help me.....it's urgent
Previous Topic (Help Me................i\'t urgent2)Next Topic (converting Column number to letters) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder