Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-22-2024, 01:33 AM
Jopo Jopo is offline VBA to F+R text + logo in header, body, footer in multiple folders Windows 10 VBA to F+R text + logo in header, body, footer in multiple folders Office 2016
Novice
VBA to F+R text + logo in header, body, footer in multiple folders
 
Join Date: Apr 2024
Posts: 5
Jopo is on a distinguished road
Default VBA to F+R text + logo in header, body, footer in multiple folders


Hello all,

Thank you for helping out.
I am not having much luck in trying to get a code to work. I have tried a few with limited success and then I come across this site. So I will try to make sure I give you all the information I / we are trying to do.
We have many policy documents, work safe, induction policies, safety policies swms etc that are in many different folders. This is literally how we have purchased these. Now we need to insert our company details amongst others into word documents plus a logo.

Contents of the word docs are

We have a header. In the header we would like to delete the existing dark placement box and insert our own logo.


In the main body there are many situations where there is repetitive entries.
i.e [Insert company name] , [Insert person in charge] and [Insert Company address]

In the footer we have
[Company name]
[Company email]
[Company phone number]
[Company address]

I am unsure if this can be done across multiple folders or One folder with the policy folders within them?

If not I could put all the word docs into one folder.

The reason i have put so much detail as I can is because reading some of the posts here it is mentioned to provide as much detail as possible.

thank you for your assistance.
Reply With Quote
  #2  
Old 04-22-2024, 08:37 PM
syl3786 syl3786 is offline VBA to F+R text + logo in header, body, footer in multiple folders Windows 10 VBA to F+R text + logo in header, body, footer in multiple folders Office 2019
Advanced Beginner
 
Join Date: Jan 2023
Posts: 78
syl3786 is on a distinguished road
Default

Quote:
Originally Posted by Jopo View Post
Hello all,

Thank you for helping out.
I am not having much luck in trying to get a code to work. I have tried a few with limited success and then I come across this site. So I will try to make sure I give you all the information I / we are trying to do.
We have many policy documents, work safe, induction policies, safety policies swms etc that are in many different folders. This is literally how we have purchased these. Now we need to insert our company details amongst others into word documents plus a logo.

Contents of the word docs are

We have a header. In the header we would like to delete the existing dark placement box and insert our own logo.


In the main body there are many situations where there is repetitive entries.
i.e [Insert company name] , [Insert person in charge] and [Insert Company address]

In the footer we have
[Company name]
[Company email]
[Company phone number]
[Company address]

I am unsure if this can be done across multiple folders or One folder with the policy folders within them?

If not I could put all the word docs into one folder.

The reason i have put so much detail as I can is because reading some of the posts here it is mentioned to provide as much detail as possible.

thank you for your assistance.
Are you implying that you're in search of a macro to execute the tasks mentioned below?
(The following should be done by word macro for all documents in a folder)

1) Locate the currently inherent dark placement box in every document's header, remove it, and substitute it with your distinct logo (for instance, in .jpg format).

2) What alterations are expected for the central segment of the document?
3) What modifications are needed for the document's footer?

It would be beneficial if you could upload a prototype document and a document showcasing the anticipated result for trial purposes.
Reply With Quote
  #3  
Old 04-22-2024, 09:10 PM
Jopo Jopo is offline VBA to F+R text + logo in header, body, footer in multiple folders Windows 10 VBA to F+R text + logo in header, body, footer in multiple folders Office 2019
Novice
VBA to F+R text + logo in header, body, footer in multiple folders
 
Join Date: Apr 2024
Posts: 5
Jopo is on a distinguished road
Default

Quote:
Originally Posted by syl3786 View Post
Are you implying that you're in search of a macro to execute the tasks mentioned below?
(The following should be done by word macro for all documents in a folder)

1) Locate the currently inherent dark placement box in every document's header, remove it, and substitute it with your distinct logo (for instance, in .jpg format).

2) What alterations are expected for the central segment of the document?
3) What modifications are needed for the document's footer?

It would be beneficial if you could upload a prototype document and a document showcasing the anticipated result for trial purposes.
Hello Syl

Thank you for taking the time out to respond. Attached is a classic document that has all the issues I mentioned in the OP. Alterations required to the 90 odd documents that are within about 60 folders.
Attached Files
File Type: docx Injury Management and Return to Work.docx (35.1 KB, 2 views)
Reply With Quote
  #4  
Old 04-22-2024, 11:15 PM
syl3786 syl3786 is offline VBA to F+R text + logo in header, body, footer in multiple folders Windows 10 VBA to F+R text + logo in header, body, footer in multiple folders Office 2019
Advanced Beginner
 
Join Date: Jan 2023
Posts: 78
syl3786 is on a distinguished road
Default

Quote:
Originally Posted by Jopo View Post
Hello Syl

Thank you for taking the time out to respond. Attached is a classic document that has all the issues I mentioned in the OP. Alterations required to the 90 odd documents that are within about 60 folders.
Please follow these steps:
  1. Execute the "ReplaceShapeInMultipleDocuments" function.
  2. Choose the folder that houses the document on which you'd like to run the macro.
  3. The macro will be applied to the selected folder's .docx files.

IMPORTANT: It's prudent to test on a few example documents before full execution.
Pending your response to my question, this macro is currently set to only identify and replace the rectangle located in the header with a specific image. You will need to determine the size of the image yourself. Moreover, don't forget to modify the image path as required.

Code:
Sub ReplaceShapeInMultipleDocuments()

    Dim folderPath As String
    Dim fileInFolder As String
    Dim doc As Document
    Dim dialogFolder As FileDialog
    
    ' Create a FileDialog object as a Folder Picker dialog box
    Set dialogFolder = Application.FileDialog(msoFileDialogFolderPicker)
    
    ' Allow the user to select multiple folders
    dialogFolder.AllowMultiSelect = True
    
    ' Show the dialog box
    If dialogFolder.Show = -1 Then
        ' Loop through each selected folder
        For i = 1 To dialogFolder.SelectedItems.Count
            ' Get the path of the folder
            folderPath = dialogFolder.SelectedItems(i)
            
            ' Get the first .docx file in the folder
            fileInFolder = Dir(folderPath & "\*.docx", vbNormal)
            
            ' Loop through each .docx file in the folder
            While fileInFolder <> ""
                ' Open the document
                Set doc = Documents.Open(folderPath & "\" & fileInFolder)
                
                ' Call the ReplaceShapeWithImage macro
                ReplaceShapeWithImage doc
                
                ' Close the document and save the changes
                doc.Close SaveChanges:=wdSaveChanges
                
                ' Get the next .docx file in the folder
                fileInFolder = Dir()
            Wend
        Next i
    End If
End Sub

Sub ReplaceShapeWithImage(doc As Document)
    Dim shp As Shape
    Dim imagePath As String
    Dim width As Single
    Dim height As Single
    
    ' Set the path to your image
    imagePath = "C:\Q.png"
    
    ' Prompt the user to input the size of the image
    width = 100
    height = 20
    
    ' Loop through each section in the document
    For Each sec In doc.Sections
        ' Loop through each header in each section
        For Each hdr In sec.Headers
            ' Loop through each shape in each header
            For Each shp In hdr.Shapes
                ' Check if the shape is the one we want to replace
                If shp.Name = "Rectangle 197" Then
                    ' Delete the old shape
                    shp.Delete
                    
                    ' Add the new image
                    Set shp = hdr.Shapes.AddPicture(imagePath, False, True, 0, 0, width, height)
                    
                    ' Set the name of the new shape to the old shape's name
                    shp.Name = "Rectangle 197"
                    
                    ' Center the image in the header
                    shp.Left = (hdr.Range.Sections(1).PageSetup.PageWidth - shp.width) / 2
                    
                    ' Exit the sub after replacing the shape
                    Exit Sub
                End If
            Next shp
        Next hdr
    Next sec
End Sub
Reply With Quote
  #5  
Old 04-23-2024, 03:35 AM
Jopo Jopo is offline VBA to F+R text + logo in header, body, footer in multiple folders Windows 10 VBA to F+R text + logo in header, body, footer in multiple folders Office 2019
Novice
VBA to F+R text + logo in header, body, footer in multiple folders
 
Join Date: Apr 2024
Posts: 5
Jopo is on a distinguished road
Default

Hello Syl,

Thank you. That worked a treat. Some minor issues where the Text moved up the page to then be overlapping the logo in some files. But I can get around that if I have to. I appreciate the help you have provided thus far.

I am really trying hard to understand what it is you have done so I understand how it is being done. I am having no luck inserting find and replace text in the body of the doc and also in the footer. Appreciate any help.
Reply With Quote
  #6  
Old 04-23-2024, 04:08 AM
Jopo Jopo is offline VBA to F+R text + logo in header, body, footer in multiple folders Windows 10 VBA to F+R text + logo in header, body, footer in multiple folders Office 2019
Novice
VBA to F+R text + logo in header, body, footer in multiple folders
 
Join Date: Apr 2024
Posts: 5
Jopo is on a distinguished road
Default

Not all files have headers and footers.

So now I am thinking I need to start off with remove all headers and footers.
Then Insert header on first page with LOGO and footer on last page with company details. i.e address Phone, email address etc. Sorry for being a pain. i am really trying hard to make sure I give all the correct information the first time.
Reply With Quote
  #7  
Old 04-23-2024, 06:05 AM
syl3786 syl3786 is offline VBA to F+R text + logo in header, body, footer in multiple folders Windows 10 VBA to F+R text + logo in header, body, footer in multiple folders Office 2019
Advanced Beginner
 
Join Date: Jan 2023
Posts: 78
syl3786 is on a distinguished road
Default

Quote:
Originally Posted by Jopo View Post
Not all files have headers and footers.

So now I am thinking I need to start off with remove all headers and footers.
Then Insert header on first page with LOGO and footer on last page with company details. i.e address Phone, email address etc. Sorry for being a pain. i am really trying hard to make sure I give all the correct information the first time.
To better understand your requirements, I suggest providing a sample document and an expected result document. This will enable us to clearly understand what you're trying to achieve and provide a more accurate and effective response.
Reply With Quote
  #8  
Old 04-23-2024, 06:57 AM
Jopo Jopo is offline VBA to F+R text + logo in header, body, footer in multiple folders Windows 10 VBA to F+R text + logo in header, body, footer in multiple folders Office 2019
Novice
VBA to F+R text + logo in header, body, footer in multiple folders
 
Join Date: Apr 2024
Posts: 5
Jopo is on a distinguished road
Default

Quote:
Originally Posted by syl3786 View Post
To better understand your requirements, I suggest providing a sample document and an expected result document. This will enable us to clearly understand what you're trying to achieve and provide a more accurate and effective response.
Thank you SYL. Please give me some time on this. What I assumed was one format of files we recieved has now turned into two at least. I will try to provide more detailed information tomorrow and what I am hoping to achieve. Thank you SYL for your time
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Insert Image(logo) into header for multiple Word Docs Axis Word VBA 4 02-09-2022 10:34 PM
Adding text to the header and footer without removing all other content in the header and footer digitalelise Word VBA 2 10-23-2019 02:58 AM
VBA to F+R text + logo in header, body, footer in multiple folders How do I lock an editable text box header and stop it moving with the rest of the main body text? thegaffa Word 6 09-28-2018 09:21 AM
Locking Header/Footer on Document but still be able to edit body text (size, font, bold, etc) Porkie96 Word 1 06-21-2018 01:56 PM
VBA to F+R text + logo in header, body, footer in multiple folders Created VBA to Find and Replace in Body, Header and Footer with Highlighting the replacement text QA_Compliance_Advisor Word VBA 11 09-23-2014 04:40 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:15 PM.


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