![]() |
|
|
|
#1
|
|||
|
|||
|
Paul,
I experimented a little with these two files I have attached. Two scenarios with two different results:
|
|
#2
|
|||
|
|||
|
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! |
|
#3
|
||||
|
||||
|
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] |
|
#4
|
|||
|
|||
|
Just a note that you seem to be describing a Table column.
|
|
#5
|
||||
|
||||
|
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] |
|
#6
|
|||
|
|||
|
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 ![]() 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
Last edited by kykyryky; 01-25-2024 at 08:29 AM. Reason: adding |
|
#7
|
||||
|
||||
|
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] |
|
#8
|
|||
|
|||
|
Yes, I know.
|
|
#9
|
|||
|
|||
|
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! |
|
#10
|
|||
|
|||
|
the file uploaded here.
|
|
#11
|
|||
|
|||
|
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. |
|
#12
|
|||
|
|||
|
And yes, the files here, if it helps...
|
|
#13
|
|||
|
|||
|
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. |
|
| Tags |
| macropod |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Find & Replace in Header/Footer in 1000 files
|
amodiammmuneerk@glenmarkp | Word | 12 | 03-05-2018 03:31 AM |
Find & Replace in Header/Footer
|
PReinie | Word | 6 | 01-22-2014 06:45 PM |
How to apply a list style to multiple Word documents?
|
MrSnrub | Word | 4 | 06-19-2013 07:32 AM |
Apply template to multiple documents
|
Oliver Beirne | Word VBA | 2 | 04-24-2012 04:49 AM |
convert multiple csv files to multiple excel files
|
mit | Excel | 1 | 06-14-2011 10:15 AM |