Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-28-2016, 01:46 PM
Carchee Carchee is offline Replace or apply new header in multiple files Windows 10 Replace or apply new header in multiple files Office 2013
Advanced Beginner
Replace or apply new header in multiple files
 
Join Date: Dec 2013
Posts: 46
Carchee is on a distinguished road
Default

Paul,

I experimented a little with these two files I have attached. Two scenarios with two different results:


  1. When I use the Test.doc file as the source "Replace Header" file it works
  2. When I use the Test2.doc file as the source "Replace Header" file it doesn't work as shown in the pic from post #26.
Which leaves me to conclude that the code is working but for some reason it's not working with this one file......frustrating
Attached Files
File Type: doc Test.doc (32.0 KB, 21 views)
File Type: doc Test2.doc (29.5 KB, 14 views)
Reply With Quote
  #2  
Old 05-30-2017, 08:44 AM
msir msir is offline Replace or apply new header in multiple files Windows 10 Replace or apply new header in multiple files Office 2013
Novice
 
Join Date: May 2017
Posts: 1
msir is on a distinguished road
Default

Carchee,

Is there any way you can post your code file? I am looking to do the exact same thing as you but could not get it working with the codes that were posted.

Thanks in advance!
Reply With Quote
  #3  
Old 06-29-2016, 10:42 AM
macropod's Avatar
macropod macropod is offline Replace or apply new header in multiple files Windows 7 64bit Replace or apply new header in multiple files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Your documents have different page layouts - Test1 has a std page layout but Test2 has a 'different first page' setup'. The macro is not coded for the latter, as it references only:
wdHeaderFooterPrimary
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 03-11-2023, 08:42 PM
Charles Kenyon Charles Kenyon is offline Replace or apply new header in multiple files Windows 11 Replace or apply new header in multiple files Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,536
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Just a note that you seem to be describing a Table column.
Reply With Quote
  #5  
Old 01-25-2024, 05:23 AM
macropod's Avatar
macropod macropod is offline Replace or apply new header in multiple files Windows 10 Replace or apply new header in multiple files Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

There is no need for the .bas file. Simply press Alt-F11 then insert the code into the appropriate code module (e.g. 'ThisDocument').

For PC macro installation & usage instructions, see: Installing Macros
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 01-25-2024, 08:24 AM
kykyryky kykyryky is offline Replace or apply new header in multiple files Windows 11 Replace or apply new header in multiple files Office 2021
Novice
 
Join Date: Jan 2024
Posts: 7
kykyryky is on a distinguished road
Default Thank you! Yet little issues...

Thank you. Yet this is a bit confusing to me, honestly. Looking for where to paste it and such.

Anyway:

1. This (header to footer) seemed to work before, yet now the same code gives me an error.
Code:
Sub Test()
Dim wdDocTgt As Document, wdDocSrc As Document
Set wdDocSrc = ActiveDocument
wdDocSrc.Sections.First.Headers(wdHeaderFooterPrimary).Range.Copy
wdDocSrc.Sections.First.Footers(wdHeaderFooterPrimary).Range.PasteAndFormat wdFormatOriginalFormatting
End Sub
Both for dummy files and our corporate ones. Any idea, please? I am not aware of changing anything from the time it worked these several hours ago.


Edit: Seems not/to work randomly on exactly the same files, machine, everyhing.



2. This (header to other docs) does not do anything if on a mapped network drive (simply nothing happens), and somehow (so far incorrectly, more later) works on local. Can this be solved in some manner, please? Could it be due to access restrictions/authentication? Yet me myself, I do have access with full rights there in the folders.

Code:
Sub UpdateDocumentHeaders()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, StrTxt As String
Dim wdDocTgt As Document, wdDocSrc As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
StrTxt = InputBox("Text to add to headers? e.g. ""March 1, 2018""")
If Trim(StrTxt) = "" Then Exit Sub
Set wdDocSrc = ActiveDocument
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
    If strFolder & "\" & strFile <> wdDocSrc.FullName Then
        Set wdDocTgt = Documents.Open(FileName:=strFolder & "\" & strFile, _
        AddToRecentFiles:=False, Visible:=False)
        With wdDocTgt
            .Sections(1).Headers(wdHeaderFooterPrimary).Range.InsertAfter StrTxt
            .Close SaveChanges:=True
        End With
    End If
    strFile = Dir()
Wend
Set wdDocSrc = Nothing: Set wdDocTgt = Nothing
Application.ScreenUpdating = True
End Sub

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Once again, huge thanks for doing this.

Last edited by kykyryky; 01-25-2024 at 08:29 AM. Reason: adding
Reply With Quote
  #7  
Old 01-25-2024, 02:36 PM
macropod's Avatar
macropod macropod is offline Replace or apply new header in multiple files Windows 10 Replace or apply new header in multiple files Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

The test code you're using merely copies & pastes the active document's primary header over its footer. It will produce an error if there's no primary header.

The UpdateDocumentHeaders code you posted doesn't replicate anything; all it does is add whatever you've typed at the InputBox prompt to the primary header of all documents in the selected folder.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 01-26-2024, 12:14 AM
kykyryky kykyryky is offline Replace or apply new header in multiple files Windows 11 Replace or apply new header in multiple files Office 2021
Novice
 
Join Date: Jan 2024
Posts: 7
kykyryky is on a distinguished road
Default

Yes, I know.
Reply With Quote
  #9  
Old 01-26-2024, 02:17 AM
kykyryky kykyryky is offline Replace or apply new header in multiple files Windows 11 Replace or apply new header in multiple files Office 2021
Novice
 
Join Date: Jan 2024
Posts: 7
kykyryky is on a distinguished road
Default

Hello, so tried running this header/footer copy from > to on the same pair of two docs. One with a header (called source) and one without (called victim).

When ran on a local C: drive, works just fine.
When ran on a mapped network drive U:, does nothing:



Can this be solved? Thank you!



Secondly, when running this header > footer (as a test), it shows an error:



Any idea, please?

Many thanks!
Reply With Quote
  #10  
Old 01-26-2024, 02:33 AM
kykyryky kykyryky is offline Replace or apply new header in multiple files Windows 11 Replace or apply new header in multiple files Office 2021
Novice
 
Join Date: Jan 2024
Posts: 7
kykyryky is on a distinguished road
Default

the file uploaded here.
Attached Files
File Type: docx source.docx (18.0 KB, 2 views)
Reply With Quote
  #11  
Old 01-26-2024, 02:58 AM
kykyryky kykyryky is offline Replace or apply new header in multiple files Windows 11 Replace or apply new header in multiple files Office 2021
Novice
 
Join Date: Jan 2024
Posts: 7
kykyryky is on a distinguished road
Default

And if you would not mind me asking yet another question at the same time...

Here I took a source with a header and footer and wanted them to be copied into a victim with a different set. As seen here:



and ran the code with no change. Worked "quite nice":


As you can see, they are not completely the same. The sizing of the text went from 9 to 11, the butterfly picture went down to the line, the whole footer went up and left.



The change is not a function of the target style. Look, here I used a very wild set of properties for the victim, yet the result is the same as above.



Also, I noticed that the copied picture is not the same "object" as the source. Look:


If you are accepting donations, I will gladly donate for your help.
Reply With Quote
  #12  
Old 01-26-2024, 03:00 AM
kykyryky kykyryky is offline Replace or apply new header in multiple files Windows 11 Replace or apply new header in multiple files Office 2021
Novice
 
Join Date: Jan 2024
Posts: 7
kykyryky is on a distinguished road
Default

And yes, the files here, if it helps...
Attached Files
File Type: docx source.docx (41.7 KB, 3 views)
File Type: docx victim.docx (15.3 KB, 3 views)
Reply With Quote
  #13  
Old 01-26-2024, 07:27 AM
Italophile Italophile is offline Replace or apply new header in multiple files Windows 11 Replace or apply new header in multiple files Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

Quote:
Originally Posted by kykyryky View Post
And yes, the files here, if it helps...
The page layout of the two files is different, which accounts for the header appearing in a different place.

Although the text in the header of the source document states that it is in 9pt, it is actually 11pt, so it isn't any different after copying.
Reply With Quote
Reply

Tags
macropod

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace or apply new header in multiple files Find & Replace in Header/Footer in 1000 files amodiammmuneerk@glenmarkp Word 12 03-05-2018 03:31 AM
Replace or apply new header in multiple files Find & Replace in Header/Footer PReinie Word 6 01-22-2014 06:45 PM
Replace or apply new header in multiple files How to apply a list style to multiple Word documents? MrSnrub Word 4 06-19-2013 07:32 AM
Replace or apply new header in multiple files Apply template to multiple documents Oliver Beirne Word VBA 2 04-24-2012 04:49 AM
Replace or apply new header in multiple files convert multiple csv files to multiple excel files mit Excel 1 06-14-2011 10:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:38 AM.


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