![]() |
|
#1
|
|||
|
|||
|
Hello,
I have a task, I need to change the footer of a lot of file in a directory, remove and old jpg a add a new jpg to it. The jpg is in another document, but of course it can be saved in a separate file. Could anybody help, pls? thank you |
|
#2
|
|||
|
|||
|
it will be something like this:
Code:
Selection.InlineShapes.AddPicture FileName:= _
"H:\My Documents\VBA\picture.jpg", LinkToFile:=False, _
SaveWithDocument:=True
|
|
#3
|
||||
|
||||
|
You could use code like:
Code:
Sub UpdateFooters()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, Rng As Range
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, _
AddToRecentFiles:=False, Visible:=False)
With wdDoc
With .Sections.First.Footers(wdHeaderFooterPrimary)
If .InlineShapes.Count <> 0 Then
Set Rng = .InlineShapes(1).Range
With Rng
.InlineShapes(1).Delete
.InlineShapes.AddPicture FileName:="H:\My Documents\VBA\picture.jpg", _
LinkToFile:=False, SaveWithDocument:=True
End With
End If
End With
.Close SaveChanges:=False
End With
strFile = Dir()
Wend
Set wdDoc = 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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#4
|
|||
|
|||
|
Hello,
many thanks for the code, I really appreciate it. |
|
#5
|
||||
|
||||
|
Cross-posted at: http://windowssecrets.com/forums/sho...-of-a-doc-file
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to convert a text file to an Excel file with the data format automatically?
|
mradmin | Excel | 6 | 10-16-2013 10:34 AM |
excel cannot open the file .xlsx because the file format or file extension is not val
|
teddysika | Excel | 1 | 11-22-2012 06:06 AM |
error: You are attempting to save a file format that is blocked by file block setting
|
zatlas1 | Office | 8 | 04-28-2012 02:37 PM |
Microsoft office hanging when opening file directory
|
EnlightenWeb | Office | 1 | 12-21-2011 01:56 AM |
| Auto-File Naming/ Default Directory Saves | sgill32 | Word | 2 | 11-06-2008 02:12 PM |