Results 1 to 2 of 2
2013-02-02, 23:12 #1
- Join Date
- Jan 2007
- Massachusetts, USA
- Thanked 0 Times in 0 Posts
Change graphic folder path link in folder full of documents
I am using MS Word 2010 and would like to:
Swap graphic file path:
<c>01 Graphics Catalog<c>router.png
I can get column A in a spreadsheet to point to column B in the same spreadsheet
and take the old physical file name of a graphic (from column A) and rename it to a new physical file graphic name (in column B).
But, now I want a macro to open the document (.mif file in this case) from which the graphics are lilnked and then reference a spreadsheet and
apply the line for line graphics file name path to the path listed in the .mif file.
Mif is a FrameMaker (.fm) file format that was saved to .mif so that I could get inside the document, as if in text mode.
I have attached what I have from many years back with MS Word 2003/2007. Please let me know if this is possible with MS Word 2010.
Thanks in advance for any assistance provided.
There is some code text below from this forum, several years ago.
Sub RenameFiles() ' Modify as needed but keep trailing backslash Const strPath = "C:\Temp1\" ' Variables Dim strFile As String Dim r As Long Dim n As Long Dim app As Object Dim doc As Object Dim blnStart As Boolean On Error Resume Next ' Try to get running instance of Word Set app = GetObject(, "Word.Application") ' If not active yet... If app Is Nothing Then ' ... try to start Word Set app = CreateObject("Word.Application") ' If that fails... If app Is Nothing Then ' ... tell user and get out MsgBox "Can't start Word.", vbExclamation Exit Sub End If ' Remember that we started Word blnStart = True End If On Error Goto ErrHandler ' Last used row in column D n = Range("D" & Rows.Count).End(xlUp).Row ' Loop through documents strFile = Dir(strPath & "*.mif") Do While Not strFile = "" ' Open document Set doc = app.Documents.Open(strPath & strFile) ' Show field codes doc.ActiveWindow.View.ShowFieldCodes = True With doc.Content.Find ' Initialize find/replace .ClearFormatting .Replacement.ClearFormatting .MatchCase = False .MatchWildcards = False ' Loop through rows of worksheet, starting at row 5 For r = 5 To n ' Replace text from column D with that in column E .Execute FindText:=Range("D" & r), ReplaceWith:=Range("E" & r), _ Replace:=2 ' wdReplaceAll Next r End With ' Hide field codes doc.ActiveWindow.View.ShowFieldCodes = False ' Close and save document doc.Close SaveChanges:=True ' On to next document strFile = Dir Loop ExitHandler: ' Clean up On Error Resume Next doc.Close SaveChanges:=False Set doc = Nothing ' If we started Word... If blnStart Then ' ... exit it app.Quit SaveChanges:=False End If Set app = Nothing Exit Sub ErrHandler: MsgBox Err.Description, vbExclamation Resume ExitHandler End Sub
Last edited by macropod; 2013-02-03 at 00:34. Reason: Added code tags & formatting
2013-02-03, 00:40 #2
- Join Date
- May 2002
- Canberra, Australian Capital Territory, Australia
- Thanked 417 Times in 346 Posts
UnlessFrameMaker has an API that is accessible to vba, you're unlikely to be able to do this. In any event, since the data are in Excel, it would make more sense to do the work from there (or from Framemaker) than involving yet another application (Word).
PS: When posting code, please use the code tags. They're designated by the # symbol on the 'Advanced' tab's menu.
Last edited by macropod; 2013-02-03 at 00:42.Cheers,
[MS MVP - Word]