Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 31

Thread: Word report generation page/header problem.

  1. #1
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location

    Question Word report generation page/header problem.

    Hey everyone,

    Got a quick questions about a problem that I am having. I thought I might post it here first before I try to solve it myself because there might be an easy solution to it.
    Basically, I have a C# program using VBA to control a Word document which is a template for a survery. The C# program uses Find/Replace to fill in appropriate fields in the survey.
    The survery can be 2 - 5 pages long and it is for a mall. In the header of each survery I have it saying "Mall 1 mall_name, mall_address", and I am also using the Page {PAGE} out of {NUMPAGES} in the right side of my header. Everything thing works ok.
    I now have to generate a batch of these surveys. I want them all to be one Word document. So i am using InsertFile so insert one copy do all the find/replace, go to a next page and insert another copy and so on. They problem now I have is with the headers. I need the header of the first survey to say Mall 1 mall_name1, mall_address_1, and then when we start survery 2 the header needs to say Mall 2 mall_name2, mall_address_2 and so on.
    The pages at the start of survery one have to be One to SizeOfSurvey1, then at the start of survey two One to SizeOfSurver2 and so on...

    Can anyone suggest a way to do this?

    Mike

  2. #2
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    First of all, I'm no coder, okay? I'm just a Word geek, and I apologize for making you wait so long for a response. I had no idea "non-VBA" questions were being asked.

    I don't think I can help you with the mall1, mall2 bit.

    But, the NUMPAGES is wrong. Go to Insert-Field, choose numbering and choose SECPAGES and you'll get the number you need for the document as long as you're inserting next-page section breaks.
    ~Anne Troy

  3. #3
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    1. Why do you want it to be one Word document? This seems to be asking for trouble....as you have discivered. From a design point of view, could you tell me why you have it as one document?

    2. Make a Section break by code before your bring in the next file.

    3. Move the Selection one character into the new section.

    4. IMMEDIATELY make all headers NOT Same as previous.

    5. Bring in your file.

    Now, how are you getting "Mall 1 mall_name, mall_address" to become Mall 2, mall_name2"?

  4. #4
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location
    Hey guys,

    Thanks for the response. I am trying to make this one document so that the person so that when the user asks to generate 15 surverys, he/she clicks on a button and 15 get generated and he/she can just click print and all of them would be printed.
    Dreamboat, so your saying using {PAGE} and {SECPAGES} would work as long as I separate each survery by a section break right?

    fumei, the way I am doing it right now is that all headers will be the same. They will be filled with the information from the last survey. This makes sense since the program used the last survey's information (mallname, malladdress, etc) to set the headers.
    the procedure you wrote will make the header of each section different basically?
    and also when you say Make a section break, is this a Next Page break right??


    Thanks
    Mike

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    You are not consistent. Your last post:
    the way I am doing it right now is that all headers will be the same
    and the original post:
    I need the header of the first survey to say Mall 1 mall_name1, mall_address_1, and then when we start survery 2 the header needs to say Mall 2 mall_name2, mall_address_2 and so on
    Can't have it both ways. You chose to make it one document. therefore either the header is the same, or it is not. Your original post seems to want to have different headers, this last seems (but I am not totally sure) that you want same headers. Please clarify.

    If you make a Section break, make it a Next Page section break. This makes....a new section. A new section has its own headers. However, by default, Word makes those headers the same as the previous Section. It seems like you want different headers.
    They will be filled with the information from the last survey. This makes sense since the program used the last survey's information (mallname, malladdress, etc) to set the headers.
    You must explain this very very carefully. This sounds like code.

    What last survey? Are you opening a previous file? Please explain, precisely, how your headers are being filled.

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Dreamboat would know better than me, but would this not be a suitable use for the Office Binder? (I've never found one before)
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Can't really use binder anymore since they canned it...
    ~Anne Troy

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Oh well...
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location
    Ok step by step:

    Sorry my posts need some decrypting.

    1) I have a file (.doc) while is a template for a survey. In it I have a bunch of special keywords (<<mallname>>, <<mallstate>>, etc) in where the input data needs to go.

    2) I open this file. I am using a C# program which calls the VBA.

    3) I find/replace all the things that are needed (Example: all the "<<mallname>>" with 10th District Mall, and "<<mallstate>>" with New Jersey)

    4) I do a page break and I do an InsertFile and insert another copy of this template (with all the special keywords) into the current location of this document.

    5) I do find/replace on all the things again. And I again replace the keywords with data only this time from another mall.

    This is the main loop. My problem is that the template is 3 pages, but it can expand. I need it so that the headers on each survery refrect the data in the survey, and the pages are numbered from 1 to the last page number of that survery.

    Lets say i generated a document which has 3 surveys,

    Survey 1) mall1 and it 10 is pages in length
    Survey 2) another being mall2 and it is 2 pages in length
    Survey 3) third being mall3 and it is 3 pages in length

    The whole thing adds to 15 pages.

    So here is a graphical example:

    Actual PageNum: PageItNeedsToBe: HeaderItNeedsToBe

    1 1 mall1_header
    2 2 mall1_header
    3 3 mall1_header
    4 4 mall1_header
    5 5 mall1_header
    6 6 mall1_header
    7 7 mall1_header
    8 8 mall1_header
    9 9 mall1_header


    10 10 mall1_header



    11 1 mall2_header

    12 2 mall2_header



    13 1 mall3_header

    14 2 mall3_header

    15 3 mall3_header



    Let me know what you think





    Mike

  10. #10
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    I can't figure out why you're not just using a mail merge...
    ~Anne Troy

  11. #11
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location
    I try to avoid Mail Merge as much as possible. Especially on Word 2000

  12. #12
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location
    Its buggy as hell especially in the earlier versions

  13. #13
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    What??

    I think perhaps you don't know how to use it. I have never heard anyone refer to mail merge as being "buggy" at all. And the truth is, they've ruined it in the newer versions.
    ~Anne Troy

  14. #14
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I agree with that sentiment DB, but maybe he still has the Binder?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  15. #15
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Sorry, MD. I don't really see how binder comes into play, either.
    ~Anne Troy

  16. #16
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location
    Using mailmerge for the find/replace you mean right?

  17. #17
    VBAX Regular
    Joined
    Sep 2004
    Posts
    65
    Location
    I don't know whether this is help hinderance or irrelevant, but in my application I use loops to generate/process multiple documents (each with their own header/Footers).

    How about using a loop to generate all surveys as independent docs from one main macro?

  18. #18
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Mike: Do you have a data file? Would something like this be easier?
    http://www.vbaexpress.com/kb/getarticle.php?kb_id=381
    ~Anne Troy

  19. #19
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I still would like to know how you are filling the headers. I understand what you want as headers.

    Do not a page break. Use a Section break.
    Make the new Section not Same as previous

  20. #20
    VBAX Regular
    Joined
    Mar 2005
    Posts
    67
    Location
    Hey guys,
    Appreciate for all your help.
    Dreamboat my data file is SQL Server. Im reading data from there.
    fumei: Use a secion break. Ok, what did you mean Make the new Section not Same as previous.

    I was trying to write some text then add a section break and add some more text in the second section. Then i went to the first section's headers/footers and named it "Section 1", after that I went into the second Section's headers/footers and named it "Section 2". After i did that section 1's header/footer also became "Section 2". So headers/footers are not section dependant.

    Maybe theres an option that can make them section dependant that i dont know about??


    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •