Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-09-2013, 06:08 AM
hklein hklein is offline Replacing jpg file in each file of a directory Windows XP Replacing jpg file in each file of a directory Office 2007
Novice
Replacing jpg file in each file of a directory
 
Join Date: Jul 2011
Posts: 23
hklein is on a distinguished road
Default Replacing jpg file in each file of a directory

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
Reply With Quote
  #2  
Old 10-09-2013, 08:09 AM
hklein hklein is offline Replacing jpg file in each file of a directory Windows XP Replacing jpg file in each file of a directory Office 2007
Novice
Replacing jpg file in each file of a directory
 
Join Date: Jul 2011
Posts: 23
hklein is on a distinguished road
Default

it will be something like this:
Code:
 Selection.InlineShapes.AddPicture FileName:= _
        "H:\My Documents\VBA\picture.jpg", LinkToFile:=False, _
        SaveWithDocument:=True
But how I define, that it will be done in the footer?
Reply With Quote
  #3  
Old 10-11-2013, 12:47 AM
macropod's Avatar
macropod macropod is offline Replacing jpg file in each file of a directory Windows 7 32bit Replacing jpg file in each file of a directory Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

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
You may want to add a bit more to control the image size too.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 10-12-2013, 08:42 AM
hklein hklein is offline Replacing jpg file in each file of a directory Windows XP Replacing jpg file in each file of a directory Office 2007
Novice
Replacing jpg file in each file of a directory
 
Join Date: Jul 2011
Posts: 23
hklein is on a distinguished road
Default

Hello,

many thanks for the code, I really appreciate it.
Reply With Quote
  #5  
Old 10-14-2013, 04:40 PM
macropod's Avatar
macropod macropod is offline Replacing jpg file in each file of a directory Windows 7 32bit Replacing jpg file in each file of a directory Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

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]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing jpg file in each file of a directory How to convert a text file to an Excel file with the data format automatically? mradmin Excel 6 10-16-2013 10:34 AM
Replacing jpg file in each file of a directory 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
Replacing jpg file in each file of a directory 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
Replacing jpg file in each file of a directory 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

Other Forums: Access Forums

All times are GMT -7. The time now is 07:29 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