Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 





Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > Microsoft Support > Microsoft Office support
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read

Microsoft Office support MS Office support forum

Reply
 
Thread Tools
Old 07-24-2008, 01:23 AM   #1 (permalink)
Registered User
 
Join Date: Jul 2008
Posts: 1
OS: Win XP


Macro Paragraph Style

Hello All,

I have text having some particular style in a page while using Macro. The word document has about 90 pages. The text having style starts from 9th page. So I reach 9th page and read the first text having the style and set it as header.There are some more text's having same style on same page.

My problem is that I have to jump to next page to select the first text having style and set as header while ignoring other text's that foloow on the same page. Is there a solution by using Paragraph? As it sets all the text's of the same page.

Here is my function below:

Function setCIHeader()

Dim doc As Document
Dim objParagraph As Paragraph

'Dim pgno As Integer
Set doc = Documents.Open(ActiveDocument.path & "\cumindex.chrono.en.doc")
doc.Activate

Selection.GoTo What:=wdGoToPage, Which:=wdGoToPrevious, count:=10

pgno = getActualCurrentPageNo
'Dim n As Integer
n = 8

Do While pgno < n
pgno = getActualCurrentPageNo
goToNextPage
Loop

'Do While pgno >= 8
'Loop

'For Each itm In doc.ActiveWindow.Application.ActiveDocument.Paragraphs
For Each objParagraph In ActiveDocument.Paragraphs
'goToNextPage

With objParagraph
If objParagraph.style = "Chrono.conclusionyear" Then
'MsgBox (objParagraph.style)

.Range.Select
'goToPreviousPage
Selection.MoveUp Unit:=wdLine, count:=1
'Selection.InsertBreak Type:=wdSectionBreakContinuous
'Selection.MoveDown Unit:=wdLine, count:=1
'goToNextPage
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
LinkToPrevious
'Selection.WholeStory
'Selection.delete Unit:=wdCharacter, count:=1
Selection.MoveDown Unit:=wdScreen, count:=1
MsgBox (Trim(objParagraph.Range.text))
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.InsertAfter (vbLf)
Selection.TypeText text:=Trim(objParagraph.Range.text)
'Selection.MoveDown Unit:=wdScreen, count:=1
'Selection.MoveDown Unit:=wdLine, count:=10
'ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
'Selection.MoveDown Unit:=wdLine, count:=3
'n = getActualCurrentPageNo + 1
ActiveWindow.ActivePane.View.NextHeaderFooter
Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, count:=1
n = n + 1
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, count:=n
'Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext, count:=2
'objParagraph.style = Nothing
'Selection.GoTo What:=wdGoToTable, Which:=wdGoToNext

'ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
'If Selection.HeaderFooter.IsHeader = True Then
'Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
'LinkToPrevious

'Else
' ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
'End If

'Exit Function
End If
End With
Application.StatusBar = "Setting Header in pages...Please Wait.."
Next
doc.Close savechanges:=wdSaveChanges
Application.StatusBar = "Done..."
'Loop ''New R&D

End Function
anup.kamat is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Old 07-24-2008, 03:24 PM   #2 (permalink)
Registered User
 
Join Date: May 2008
Location: Baltimore, Maryland
Posts: 97
OS: Windows XP SP3


Re: Macro Paragraph Style

Here’s a somewhat different approach. Starting with page 9, the following example code finds text formatted with the Chrono.conclusionyear style, inserts a section break at the top of the page (this allows each page to have different header text), places the text in the header, then continues with the next page. Modify as necessary.

Code:
Function setCIHeader()
    Dim doc As Document
    Dim objParagraph As Paragraph
    Dim processpage As Long
    Dim headertext As String
    Set doc = Documents.Open(ActiveDocument.Path & "\cumindex.chrono.en.doc")
    doc.Activate
    processpage = 9
    For Each objParagraph In ActiveDocument.Paragraphs
        If Selection.Information(wdActiveEndPageNumber) > processpage Then
            processpage = processpage + 1
        Else
            With objParagraph
                If .Style = "Chrono.conclusionyear" Then
                    .Range.Select
                    headertext = Trim(.Range.Text)
                    If Selection.Information(wdActiveEndPageNumber) = processpage Then
                        Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, _
                            Name:=Trim(Str(processpage))
                        Selection.InsertBreak Type:=wdSectionBreakContinuous
                        ActiveDocument.Sections(Selection.Sections.Item(1).Index) _
                            .Headers(wdHeaderFooterPrimary).LinkToPrevious = False
                        ActiveDocument.Sections(Selection.Sections.Item(1).Index) _
                            .Headers(wdHeaderFooterPrimary).Range.Text = headertext
                        processpage = processpage + 1
                    End If
                End If
            End With
        End If
    Next objParagraph
End Function
David M58 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -7. The time now is 06:51 PM.



Copyright 2001 - 2008, Tech Support Forum

Search Engine Friendly URLs by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82