Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Help with Word Macro

Reply  
Thread Tools
pgaec's Avatar
Junior Member with 3 posts.
 
Join Date: Nov 2009
13-Nov-2009, 08:57 PM #1
Help with Word Macro
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?
Attached Thumbnails
Help with Word Macro-odd.jpg   Help with Word Macro-even.jpg  
Attached Files
File Type: docx output.docx (24.5 KB, 156 views)
pgaec's Avatar
Junior Member with 3 posts.
 
Join Date: Nov 2009
14-Nov-2009, 07:22 AM #2
I figured that my problem is due to the fact that there are no page breaks in the document, so

ActiveDocument.Bookmarks("\page").Range.Select

always selects the entire document.
Any way to overcome this? i.e, by creating a macro to add page break after every page??? Any ideas?
pgaec's Avatar
Junior Member with 3 posts.
 
Join Date: Nov 2009
15-Nov-2009, 03:04 AM #3
Reply

Tags
macro, page, word

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:04 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.