![]() |
#1
|
|||
|
|||
![]()
Sometime ago Paul assisted me with the code of inserting another document in a document (At the end).
The code is in this post. Is it possible that when this document is inserted - it also do the following: 1) Remove the existing footer and replace it by linking it with previous section footer. 2) Add a specific bookmark to the heading of inserted document. Code:
Sub insertdoc_essential() Dim Scn As Section, HdFt As HeaderFooter With ActiveDocument Set Scn = .Sections.Add(Range:=.Range.Characters.Last, Start:=wdSectionNewPage) With Scn For Each HdFt In Scn.Headers HdFt.LinkToPrevious = False .Range.Text = vbNullString Next For Each HdFt In Scn.Footers HdFt.LinkToPrevious = False .Range.Text = vbNullString Next .Range.InsertFile FileName:="p:\psk service agreements\client ongoing service agreement - Essentials.docx" While .Range.Characters.Last.Previous = vbCr .Range.Characters.Last.Previous.Delete Wend End With End With End Sub Umesh Banga Last edited by ubns; 08-24-2012 at 03:20 AM. Reason: na |
#2
|
||||
|
||||
![]()
If you want the footers connected, change:
HdFt.LinkToPrevious = False .Range.Text = vbNullString to: HdFt.LinkToPrevious = True As for the bookmark, is there anything in particular you want bookmarked?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Yes, I want the title of the document "Ongoing Advice Agreement" to be bookmarked as "Heading_OngoingAdviceAgreement \h".
Also changing the code to True does not link it with footer of previous section? Would you like to get a copy of both type of documents? Regards |
#4
|
||||
|
||||
![]() Quote:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Paul,
There are so many heading styles we have in the document that is can confusing to find. Moreover I do not have control in terms of suggesting and removing these many heading styles. I think the best solution is to run the macro or some sort of code which automatically puts that heading style. Footer - the previous footer has the wording "Statement of Advice/"Page number"" and it is not picking that up. Regards |
#6
|
||||
|
||||
![]() Quote:
Quote:
Quote:
a) there isn't another Section break before the new Section the code adds; and b) that the page layout in the previous Section doesn't have, say, a 'different first page' setup (in which case, the same applies to the new Section and the footer might not appear till the 2nd page).
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
![]()
Hi Paul,
Thanks for your prompt reply. I understand and appreciate your comment on referencing bookmark manually and that is what I have been doing, however I have found that some of the older staff (not that computer savvy with due respect) find it hard to do that. So as always if I can automate something for them it would be great help to them. Sorry about confusion with heading style. Footer: I guess the code of inserting another document -add section break. If the code does not add then there should be no section break. No the page layout in the previous section does not have different first page set up. What do you think I should try in this case? |
#8
|
||||
|
||||
![]() Quote:
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
![]()
Hi Paul,
Thanks. How can we reference a heading without a bookmark? With regards to the the code I am talking about (for the page break) see the code below (which was provided by you). I was wondering if we can delete the existing footer of newly inserted document and link it to the previous footer? Code:
Sub insertdoc_essential() Dim Scn As Section, HdFt As HeaderFooter With ActiveDocument Set Scn = .Sections.Add(Range:=.Range.Characters.Last, Start:=wdSectionNewPage) With Scn For Each HdFt In Scn.Headers HdFt.LinkToPrevious = False .Range.Text = vbNullString Next For Each HdFt In Scn.Footers HdFt.LinkToPrevious = False .Range.Text = vbNullString Next .Range.InsertFile FileName:="p:\psk service agreements\client ongoing service agreement - Essentials.docx" While .Range.Characters.Last.Previous = vbCr .Range.Characters.Last.Previous.Delete Wend End With End With End Sub |
#10
|
||||
|
||||
![]()
By doing in code the same as you'd do manually via Insert|Cross-Reference>Heading.
If you can identify the heading to bookmark it, so that you can cross-reference the bookmark, you can just as easily identify it for cross-referencing without the bookmark. Quote:
.Range.InsertFile ... Insert: Code:
For Each HdFt In Scn.Footers .Range.Text = vbNullString HdFt.LinkToPrevious = True Next
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Inserting one document into another | Bluie | Word | 5 | 05-17-2012 12:00 PM |
![]() |
tanababa | Word | 3 | 09-25-2011 03:41 AM |
Margins in multiple section document | oaty | Word | 0 | 08-15-2010 07:32 AM |
Linking within the same document | tam5070 | Word | 0 | 02-06-2009 02:21 PM |
Same As Previous - changing default when inserting/pasting | LdeMarais | Word | 0 | 09-21-2007 11:07 AM |