Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-23-2012, 05:58 PM
ubns ubns is offline Inserting Document and linking with previous section Windows 7 32bit Inserting Document and linking with previous section Office 2010 32bit
Competent Performer
Inserting Document and linking with previous section
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default Inserting Document and linking with previous section

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
Regards

Umesh Banga

Last edited by ubns; 08-24-2012 at 03:20 AM. Reason: na
Reply With Quote
  #2  
Old 08-24-2012, 02:51 PM
macropod's Avatar
macropod macropod is offline Inserting Document and linking with previous section Windows 7 64bit Inserting Document and linking with previous section Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 08-29-2012, 05:38 PM
ubns ubns is offline Inserting Document and linking with previous section Windows 7 32bit Inserting Document and linking with previous section Office 2010 32bit
Competent Performer
Inserting Document and linking with previous section
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

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

Reply With Quote
  #4  
Old 08-29-2012, 08:26 PM
macropod's Avatar
macropod macropod is offline Inserting Document and linking with previous section Windows 7 64bit Inserting Document and linking with previous section Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by ubns View Post
I want the title of the document "Ongoing Advice Agreement" to be bookmarked as "Heading_OngoingAdviceAgreement \h".
A bookmark name wouldn't have the '\h' switch. That's something you'd use in a REF field, perhaps. Also, your using of 'Heading_' as part of the name suggests you may already be using a Heading Style. In that case, you can cross-reference it (via the Heading) without creating a bookmark.
Quote:
Also changing the code to True does not link it with footer of previous section?
It does enforce a link. Of course, if the footer it's linked to is empty, you won't see anything.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 08-29-2012, 08:46 PM
ubns ubns is offline Inserting Document and linking with previous section Windows 7 32bit Inserting Document and linking with previous section Office 2010 32bit
Competent Performer
Inserting Document and linking with previous section
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 08-29-2012, 09:29 PM
macropod's Avatar
macropod macropod is offline Inserting Document and linking with previous section Windows 7 64bit Inserting Document and linking with previous section Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by ubns View Post
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.
No-one was suggesting you should remove any heading styles. What I suggested is that you can reference a particular heading without creating a bookmark. So the question becomes: Is the heading that you want to reference formatted in a heading Style? If so, it's simply a matter of inserting a cross-reference to it.
Quote:
I think the best solution is to run the macro or some sort of code which automatically puts that heading style.
You were previously asking for a bookmark, now you're referring to putting a heading Style. I have no idea what you mean.
Quote:
the previous footer has the wording "Statement of Advice/"Page number"" and it is not picking that up.
Are you sure:
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]
Reply With Quote
  #7  
Old 08-30-2012, 05:09 AM
ubns ubns is offline Inserting Document and linking with previous section Windows 7 32bit Inserting Document and linking with previous section Office 2010 32bit
Competent Performer
Inserting Document and linking with previous section
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

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?
Reply With Quote
  #8  
Old 08-30-2012, 06:08 AM
macropod's Avatar
macropod macropod is offline Inserting Document and linking with previous section Windows 7 64bit Inserting Document and linking with previous section Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by ubns View Post
I understand and appreciate your comment on referencing bookmark manually and that is what I have been doing
I haven't said anything about referencing a bookmark manually. Please read what I did say. I said you can reference a heading without a bookmark - and I didn't say anything about this being done manually, either.
Quote:
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?
I have no idea what you mean.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 09-04-2012, 07:03 PM
ubns ubns is offline Inserting Document and linking with previous section Windows 7 32bit Inserting Document and linking with previous section Office 2010 32bit
Competent Performer
Inserting Document and linking with previous section
 
Join Date: Apr 2012
Posts: 177
ubns is on a distinguished road
Default

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
Reply With Quote
  #10  
Old 09-04-2012, 08:04 PM
macropod's Avatar
macropod macropod is offline Inserting Document and linking with previous section Windows 7 64bit Inserting Document and linking with previous section Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by ubns View Post
How can we reference a heading without a bookmark?
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:
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?
After:
.Range.InsertFile ...
Insert:
Code:
    For Each HdFt In Scn.Footers
      .Range.Text = vbNullString
      HdFt.LinkToPrevious = True
    Next
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting one document into another Bluie Word 5 05-17-2012 12:00 PM
Inserting Document and linking with previous section Inserting a "Book Section" in the Bibliography of word 2007 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

Other Forums: Access Forums

All times are GMT -7. The time now is 07:22 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft