Hi,
I have a word document that has a table presented in a two column layout (See output.docx). The document is being generated using OpenXML SDK (the data comes from the database).
See odd.jpg and even.jpg (attached images) for screenshots of desired output
Things that I would like to accomplish:
----------------------------------------
PROBLEM 1: I have added a sequence to all items
{SEQ lo \# "00" }. (Select "Toggle Field Codes" to see it ) But I want the numbering to start from 1 on each page. To do this I tried :-
Code:
Sub aA()
For i = 1 To Selection.Information(wdNumberOfPagesInDocument)
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=CStr(i)
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveDocument.Bookmarks("\page").Range.Select
If Selection.Fields.Count > 0 Then
Selection.Fields(1).Code.Text = Selection.Fields(1).Code.Text & " \r1"
End If
Next
ActiveDocument.Fields.Update
End Sub
But that doesn't seem to work ( I am using Office 2007 BTW).
PROBLEM 2: See odd.jpg and even.jpg
I want to display the first entry on the current page in the header (for even pages) and I want to display the last entry on the current page in the header (for odd pages).
To do this, I was thinking...
Code:
Sub mA()
For i = 1 To Selection.Information(wdNumberOfPagesInDocument)
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=CStr(i)
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveDocument.Bookmarks("\page").Range.Select
Selection.InsertBreak Type:=wdSectionBreakContinuous
Next
For i = 1 To ActiveDocument.Sections.Count
If ActiveDocument.Sections(i).Range.Tables.Count > 0 Then
'Even Page headerText = ActiveDocument.Sections(i).Range.Tables(1).Rows(1)
'Odd Page headerText = ActiveDocument.Sections(i).Range.Tables(1).Rows(ActiveDocument.Sections(i).Range.Tables(1).Rows.Count)
End If
Next
But it is not working either. I am guessing that I am doing something wrong - I want the macro to loop through the document page by page and select the text in the document - But it always selects the entire document.
Any ideas?