+ Reply to Thread
Results 1 to 21 of 21

need help Header/Footer Building blocks

  1. #1
    Registered User
    Join Date
    09-01-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    31

    need help Header/Footer Building blocks

    hi

    I have added footer in word but it shows only number. I want to use only footer from existing pattern with word template i.e. "Accent Bar 2"

    the recorded macros in word does not work that uses building blocks.

    Any alternatives to use template


    Current Working code but confidential and page| and number comes on right side. I need at-least confidential in center and page|pagenumber right side

    Please Login or Register  to view this content.

    WordApp.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument


    Code does not work in word

    ActiveDocument.AttachedTemplate.BuildingBlockEntries("Accent Bar 2"). _
    Insert Where:=Selection.Range, RichText:=True


    Please help me in this.
    Last edited by JBeaucaire; 11-20-2013 at 08:50 PM. Reason: Added CODE tags. Moved to correct forum. Please read and abide the forum rules, link in menu bar above.

  2. #2
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: need help Header/Footer Building blocks

    As per my response to your other thread, is there a reason for not using a template formatted to your requirements?

    FWIW, it would appear your code could be reduced to something like:
    Please Login or Register  to view this content.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Registered User
    Join Date
    09-01-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: need help Header/Footer Building blocks

    It give error 5941 and doesnot work.

    Similarly, I tried before by adding direct path
    Please Login or Register  to view this content.
    My OS is win 7 and office 2007. Same code tried with other version of office 201x
    Last edited by rolta100; 11-25-2013 at 10:26 AM.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: need help Header/Footer Building blocks

    The default filepaths are different for Word 2007, 2010 & 2013. If the users don't have them stored at the default locations, you'll need to find where they are stored. So you'll need to code for all scenarios.

    For Word 2007, the default explicit path you would use is:
    .Application.Templates("C:\Users\jollymohan\AppData\Roaming\Microsoft\Document Building Blocks\1033\Building Blocks.dotx").BuildingBlockEntries("Accent Bar 2").Insert where:=.Range, RichText:=True

    For Word 2010, the default explicit path you would use is:
    .Application.Templates("C:\Users\jollymohan\AppData\Roaming\Microsoft\Document Building Blocks\1033\14\Building Blocks.dotx").BuildingBlockEntries("Accent Bar 2").Insert where:=.Range, RichText:=True

    I don't know what the default folder for office 2013 is.

    As per your other thread, you haven't answered my question as to why you're not using a template formatted to your requirements.
    Last edited by macropod; 11-25-2013 at 01:48 PM.

  5. #5
    Registered User
    Join Date
    09-01-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: need help Header/Footer Building blocks

    thanks macropod

    I have office 2007 in my office. I tried it using but it gives me error 5941 with codes one recorded in macro, second I tried earlier by adding path direct and then which is shared by you. that's why I'm forced to use this code. that same code too is also not working properly. On clicking help, it opens the page of Developers guide.

    If I'm able to use building blocks than it is good for me.

    In forum: "Unable to change properties when I paste chart from excel to word" I discussed and exactly what I'm trying to do with codes.
    Last edited by rolta100; 11-26-2013 at 03:59 AM.

  6. #6
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: need help Header/Footer Building blocks

    I will ask again: Is there a reason for not using a template formatted to your requirements? Let's see if you can answer that now that I've asked it three times ...

  7. #7
    Registered User
    Join Date
    09-01-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: need help Header/Footer Building blocks

    Actually I'm not getting question.

    But I still try to tell, I'm willing to use pre-designed templates from Microsoft. As it is giving error that's why I'm unable to use this pre-designed templates.

    Now I using the manual script as alternative that is also not working. both the conditions are not working, that's why we are discussing here.

    My goal is to designed automated word report with all conditions matched and the content in this should be formatted and well placed. that will pre-designed template or manual designed script.

    My


    hope this will satisfy the question.
    Last edited by rolta100; 11-26-2013 at 04:45 AM.

  8. #8
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: need help Header/Footer Building blocks

    Quote Originally Posted by rolta100 View Post
    But I still try to tell, I'm willing to use pre-designed templates from Microsoft. As it is giving error that's why I'm unable to use this pre-designed templates.
    You quite plainly do not understand what a template is ... See: http://office.microsoft.com/en-us/wo...101868862.aspx
    As you will learn there, you can design your own, using the building blocks as needed to create the required structure (including the Table of Contents and header/footer content), save the template, then tell your code to use your template.

  9. #9
    Registered User
    Join Date
    09-01-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: need help Header/Footer Building blocks

    thaks I will try and update my queries.

  10. #10
    Registered User
    Join Date
    09-01-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: need help Header/Footer Building blocks

    I read document, but i don't want to create template as the contents in document will be varying. that will based on excel.

    But the shared link useful for some other parts or documents.

    So any alternative is there.

  11. #11
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: need help Header/Footer Building blocks

    If you don't use a template, your code will have to tell Word where to find the building blocks for every user and for every version of Word they may use - including versions that haven't been released yet that may not even have the same building blocks. If you use your own template (and it really doesn't matter that the content will differ - that's why you have a template - you can always delete unwanted content), none of those problems will arise.

  12. #12
    Registered User
    Join Date
    09-01-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: need help Header/Footer Building blocks

    do you have any reference document for word vba as I'm coding in word for first time. Compare to this excel macro is easy

  13. #13
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: need help Header/Footer Building blocks

    To use a template of your own, forst you create one. The attached document shows what one might look like, based on what you've posted so far.

    Then, for your code to create a new document based on the template, all you'd need is:
    Set wdDoc = WordApp.Documents.Add(Template:="C:\Users\" & Environ("UserName") & "\Templates\MyTemplate.dotx")
    where "C:\Users\" & Environ("UserName") & "\Templates\" is the path to where your tewmplate is stored and "MyTemplate.dotx" is your template's name.

    Once you do that, you have a new document with all the basic features you require without needing any recourse to the Building Blocks.dotx file.

    Note: As I mentioned, the attachment is a document. To convert it to a template, use Save As in Word and choose the 'Word template (dotx)' file type. You'll also see that the document's TOC field reports an error. That's because the document doesn't yet have any headings for the field to reference. Once you add some, and update the TOC field, you'll get a properly formatted & populated Table of Contents. Similarly, I've used a Section break between the TOC and the body of the document, so that page numbering doesn't include the front matter.

    All of this is very easy if you spend a little time learning how to use Word before you try to program it.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    09-01-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: need help Header/Footer Building blocks

    Thanks..

    But still you did not get hence i'm uploading template and code (in text format used for excel).

    I have already created document template and planned to generate it only pasting data with excel, but few contents are dynamic that will be taken from Excel. that fails me to use template. after using template the cover page will be static but rest contents are dynamic the position gets disturbed while pasting images. or dynamic texts and that don't work.

    Dynamic object
    1. Header have dates that needs to be changed every time.
    2. Table have dates that needs to be changed every time.
    3. TOC will be changed based on document map every time.
    4. Footer will start number from third page.
    5. Text and paragraph will be changed in every week dynamically.

    Template will help me for cover page and TOC, but rest things will not work.

    Currently I'm facing three challenges i.e. if i don't use templates
    1. with footers - alignment of page number and confidential.
    2. TOC - that should be created in second page.
    3. this is important: while copying charts from excel using copypicture and pasting to word picture names or shape names are conflicting though I use template or not. the shape name of logo and newly added picture have same name "Picture 2" due to this alignment getting disturbed.
    Attached Files Attached Files
    Last edited by rolta100; 11-29-2013 at 09:17 AM.

  15. #15
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: need help Header/Footer Building blocks

    Quote Originally Posted by rolta100 View Post
    I have already created document template and planned to generate it only pasting data with excel, but few contents are dynamic that will be taken from Excel. that fails me to use template.
    None of this is difficult.
    Dynamic object
    1. Header have dates that needs to be changed every time.
    2. Table have dates that needs to be changed every time.
    3. TOC will be changed based on document map every time.
    4. Footer will start number from third page.
    5. Text and paragraph will be changed in every week dynamically.
    1: If the date is to be the date the document is created, use a CREATEDATE field in the header. No vba required.
    2: So insert new dates! If the dates are the only things that change and they're the only content in the cells to be changed, simply overwrite the cell content; otherwise find & replace them or replace the entire table with a new one.
    3: You can still use a TOC field in the template, without having to create a new one each time. All you need to do is to update the body of the document then use:
    WordDoc.TablesOfContents(1).Update
    4: The document I provided as a template example does that.
    5. All you need to do for your body text is to make sure you populate the document's second Section.
    Currently I'm facing three challenges i.e. if i don't use templates
    1. with footers - alignment of page number and confidential.
    2. TOC - that should be created in second page.
    3. this is important: while copying charts from excel using copypicture and pasting to word picture names or shape names are conflicting though I use template or not. the shape name of logo and newly added picture have same name "Picture 2" due to this alignment getting disturbed.
    The simple answer to all of this is to use a template. What is your objection to this?
    1& 2: The document I provided as a template example does that.
    3: If you want to add a picture to a particular location, you'd probably get better results if you bookmark the location and insert the picture in-line with text, thus:
    WordDoc.Bookmarks("123").Range.InlineShapes.AddPicture Filename:="C:\Users\socadmin\Desktop\" & "123.png", LinkToFile:=False, SaveWithDocument:=True
    If you want, you could then use the .ConvertToShape method to change the text-wrapping.

  16. #16
    Registered User
    Join Date
    09-01-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: need help Header/Footer Building blocks

    Solved:
    Add below code before using templates it will work for Header/Footer, TOC ,etc
    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Path for Built-in Building block entries
    For 2013:
    "C:\Users\admin\AppData\Roaming\Microsoft\Document Building Blocks\1033\15\Built-In Building Blocks.dotx"

    For 2010:
    "C:\Users\admin\AppData\Roaming\Microsoft\Document Building Blocks\1033\14\Built-In Building Blocks.dotx"

  17. #17
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: need help Header/Footer Building blocks

    That's all very well, but what are you going to do for Word 2007 users or if, in a future version of Word, the particular building block you seem so determined to reference changes or is deleted? And what if someone needs to run the code on a system using Office 2003 (i.e. no building blocks)? Quite apart from the fact it's easier to set up and maintain a template, a template is not susceptible to these issues. In any event, building blocks have never been needed for TOC creation.
    Last edited by macropod; 12-23-2013 at 11:35 PM.

  18. #18
    Registered User
    Join Date
    09-01-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: need help Header/Footer Building blocks

    thanks paul, I total agree with the concept you are saying and not denying this.This will be helpful for me in some another environment. But, the requirement is as such that data is variable/dynamic and the copying the charts and adding report name, TOC and headlines will be variable, so the template with static contents won't work and another challenge is that I have to maintain custom template (.dotx) in all systems. If some case/systems it gets deleted the report will not run or in such case i keep copy in ms office folders only and the system is crashed or os formatted the templates i need to copy once again in that system. which will not work with not non technical peoples.


    Quote Originally Posted by macropod View Post
    That's all very well, but what are you going to do for Word 2007 users or if, in a future version of Word, the particular building block you seem so determined to reference changes or is deleted? And what if someone needs to run the code on a system using Office 2003 (i.e. no building blocks)? Quite apart from the fact it's easier to set up and maintain a template, a template is not susceptible to these issues. In any event, building blocks have never been needed for TOC creation.
    Last edited by rolta100; 02-12-2014 at 04:24 PM.

  19. #19
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: need help Header/Footer Building blocks

    Templates can be stored in secure locations where users cannot delete them, so that's really not an issue. It's also far easier to maintain a set of templates than having everything hidden away in code that requires a programmer to maintain.

    As for the variable content, that has nothing to do with the use of templates for the content that is shared across a set of documents. Templates are for the common content - and you can have more than one, if needed. Having created a document from a template, the normal process is to add the variable content to the document. That's how Word works - every document is based on a template. I'm not suggesting anything fundamentally different to what you're now doing in that regard. A TOC, however, should not be thought of as a variable; it is a field that needs nothing more than 'ActiveDocument.TablesOfContents(1).Update' to update to reflect any changes in document headings. You really should spend more time in learning how Word works before deciding things need to be done in a particular way.

  20. #20
    Registered User
    Join Date
    09-01-2012
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: need help Header/Footer Building blocks

    sure I need, as the programming for ms word was first time for me. I faced several challenges. Please suggest me any reference book for programming in word, I tried to find lot but all are to basic only graphical based no for vba.

    Few things are good with microsoft help pages but need to search.

  21. #21
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: need help Header/Footer Building blocks

    There are plenty of books on Word & Word programming.

    For example, one you might find useful is The Secret Life of Word: A Professional Writer's Guide to Microsoft Word Automation, by R Delwood, published by XML Press in 2011(http://xmlpress.net/publications/word-secrets/). I contributed content for and did much of the technical review of this book. Although this isn't a programming book as such (though it does have some programming in it) and doesn't profess to teach you how to program, it does show how to combine Word's various tools to achieve whatever the desired result might be. That should give you a good start, because what you appear to need to use is a combination of programming and the other tools Word provides.

    You might also find it worthwhile spending some time checking out the websites of publishing companies such as XML Press and O'Reilly Media for other titles.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 07-23-2013, 10:36 AM
  2. Replies: 5
    Last Post: 03-19-2012, 06:14 PM
  3. copying building blocks
    By Peeps32 in forum Word Formatting & General
    Replies: 3
    Last Post: 11-11-2011, 01:23 PM
  4. Header and Footer
    By Pure Xtc in forum Excel General
    Replies: 3
    Last Post: 12-02-2009, 01:46 PM
  5. Header & Footer
    By ajshap1 in forum Excel General
    Replies: 2
    Last Post: 11-13-2006, 02:57 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1