PDA

View Full Version : Solved: Object links in Word Docs



sandam
04-14-2005, 02:40 AM
Hmmm... Yet another problem has arisen, this time one I thought I had licked but its come back to bite me. Essentially two of our documents have a Partner's Footer (as required by law). Now instead of having to constantly update these two header documents, they have a link to another Word Doc which is a table containing the Footer. I need to be able to update this footer once at merge (so in the AutoNew) so that the footer is current for the document produced but that any future documents will be able to have a different footer if I update the Footer.Doc. This is the code I've tried in the AutoNew of the header template but with little success. I've also tried having the link set to autoupdateas well as manual update and both times it has failed to update the footer.

Thanks in advance
Andrew;?


Sub AutoNew()
Dim i As Integer
i = CInt(ActiveDocument.Range.Information(wdNumberOfPagesInDocument))
If i > 1 Then
ActiveDocument.GoTo what:=wdGoToPage, which:=wdGoToLast
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
ActiveDocument.Range.Fields.Update
ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
ActiveDocument.GoTo wdGoToPage, wdGoToFirst
End Sub

MOS MASTER
04-14-2005, 12:06 PM
Hi Sandam, :D

Updating fields in Headers and footers is always a bit tricky.

This one updates all the fields in the document:
Sub UpdateALL()
Dim oStory As Object
Dim oToc As Object
If Documents.Count = 0 Then Exit Sub
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
Next oStory
For Each oToc In ActiveDocument.TablesOfContents
oToc.Update
Next oToc
End Sub

This is the Dirty way to do it:
Sub UpdateALL2()
Application.ScreenUpdating = False
With ActiveWindow.View
.Type = wdMasterView
.Type = wdPrintView
End With
Application.ScreenUpdating = True
End Sub

I Think it's possible to update only the fields in you're footer like:
Sub AutoNew()
Dim i As Integer
i = ActiveDocument.BuiltInDocumentProperties(14)

If i > 1 Then
ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(1).Range.Fie lds.Update
End If
End Sub

I think that in some versions of Word you have to move the selection to the section you're updating:
Sub AutoNew()
Dim i As Integer
i = ActiveDocument.BuiltInDocumentProperties(14)

If i > 1 Then
Selection.EndKey wdStory
ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(1).Range.Fie lds.Update
End If
End Sub

I'm shure one off them is gona work for you! :thumb

Enjoy..ps all is tested in 2003

sandam
04-15-2005, 02:58 AM
Dankie Joost, ek sal probeer om iets wat werk te kry met jou hulp.

And FYI i'm working in 2003 so i'm hoping that if it worked for you, it'll work for me. Maar ons sal sien ne.

Andrew;?

MOS MASTER
04-15-2005, 09:03 AM
Hi Andrew, :D

Graag gedaan h?!
Well one off them (They all worked for me) is bound to strike oil for you so.....maar we zullen het zeker gaan zien/horen...:hi:

fumei
05-02-2005, 09:55 AM
I am not sure if this was solved totally. However, it is easy to use another document as the source for footer (or header) content.

With Selection
.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertFile _
FileName:="footer.doc", Range:="", ConfirmConversions _
:=False, Link:=False, Attachment:=False
End With

will insert the contents of the footer.doc file into the CURRENT section footer. This can be adjusted for either all sections, or determined sections. It could also be adjusted to remove any current footer content, and reload the footer.doc file, if that was what you wanted. That way you could havea file that always refreshes with the current footer.doc file.

You could also do logic testing to see if you wanted to refresh, or not.

In any case, you can use InsertFile to put in footer cntent.

NOTE!!! As the footer has a default paragraph mark, you DO need to be aware of that, and adjust your footer content appropriately. This may mean moving the selection the end of the footer range before dropping a file; or moving to the range end aftewards and backspacingthe possible empty paragraph marks.

sandam
05-03-2005, 12:49 AM
Thanks Gerry, This is exactly what I was thinking of doing. I had an update fields in an auto new which worked sometimes, sometimes not. If I can have this work totally, and it looks like it will, that would be perfect. It needs to past the footer in the firstpage footer (in two of the documents its in section 1 and in the third its section 3).
Thanks again for you're help
Andrew;?

MOS MASTER
05-03-2005, 10:50 AM
It needs to past the footer in the firstpage footer (in two of the documents its in section 1 and in the third its section 3).

Hi Andy, :D

Are there other footer in the document? I mean are all footers linked? (Or does the footer have to appear in specific sections and not in other sections?)

Perhaps a little example doc whit the footers that need to be filled in it?

Enjoy! :whistle:

sandam
05-27-2005, 06:08 AM
tried inserting the document directly into the footer. however when it inserts, it insert the document into the header, not the footer, even though I specify the footer. Not sure why this happens.

MOS MASTER
05-27-2005, 09:32 AM
Hi Andy, :yes

Can you attach you're document with the code and the document with the Footer you'd like inserted? :whistle:

sandam
05-31-2005, 01:17 AM
MY apologies. I solved this one late friday and in a rush to get home for the long weekend (it was a bank holiday on monday in the UK) I neglected to mark this solved. Basically what I did was create a table in the footer and added a marker (in this case a piece of text "PARTNERSFOOTER") inside the table. then using the insert file, i replaced the text marker with the file and it worked. The "FILENAME" is a text marker to insert a specific format of fielname later on in the document creation process of our backoffice system.



Sub AutoNew()
ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
With ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage).Range
.Find.Execute findtext:="PARTNERSFOOTER"
If .Find.Found Then
.Select
Selection.Text = ""
Selection.Sections(1).Footers(wdHeaderFooterFirstPage).Range.InsertFile _
FileName:="partners footer.doc", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.Sections(1).Footers(wdHeaderFooterFirstPage).Range.Select
Selection.Collapse wdCollapseEnd
Selection.TypeBackspace
Selection.TypeText Text:="FILENAME"
End If
End With
ActiveDocument.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If
End Sub

MOS MASTER
05-31-2005, 12:25 PM
Hi Andy, :yes

Glad to see you've made it work!

Personally I wouldn't have used the selection object but that's preference...

Till we meet...:whistle:

sandam
06-01-2005, 12:36 AM
Hi Andy, :yes

Glad to see you've made it work!

Personally I wouldn't have used the selection object but that's preference...

Till we meet...:whistle:

Okay, so how would you have done it? :devil:

Andrew;?

MOS MASTER
06-01-2005, 09:33 AM
Okay, so how would you have done it? :devil:

Andrew;?
Hi Andy, :devil: :rofl:

I don't know why you are using the PARTNERSFOOTER in your footer. If that's the only thing in there than you don't need it in there even a bookmark isn't nessecary.

At the end you insert FILENAME as text? That's kinda strange shouldn't that be the Filename field?

If so you can add that field to partners footer.doc in the right place and it will be inserted as wel.

Then all is left would be something like this:

Sub AutoNew()
Dim oRange As Word.Range
Set oRange = Application.ActiveDocument.Sections(1). _
Footers(wdHeaderFooterFirstPage).Range

oRange.InsertFile _
FileName:="partner footer.doc"

Set oRange = Nothing
End Sub


And that would be sufficient. I would advice you to put the entire path to partner footer.doc for speed though!

Enjoy! :whistle:

sandam
06-02-2005, 12:45 AM
The filenames we use are of a special format that the standard field in word doesn't give so i have to generate it myself. :banghead: Otherwise, maybe i'll give your method a bash later on. At the moment we're rolling out next week so if it works : pray2: , i'm not fixing it. :whistle:

Andrew;?

MOS MASTER
06-02-2005, 09:43 AM
The filenames we use are of a special format that the standard field in word doesn't give so i have to generate it myself. :banghead: Otherwise, maybe i'll give your method a bash later on. At the moment we're rolling out next week so if it works : pray2: , i'm not fixing it. :whistle:

Andrew;?
Hahaha...Ok Andy...

Yepz like I said before if it works don't change it....(You have limited time as is...) :whistle: