Results 1 to 6 of 6

Thread: Linked graphic

  1. #1
    New Lounger
    Join Date
    Apr 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have been trying unsuccessfully to create a macro which runs on selected files in Word 2003. If a file contains a linked graphic, it writes the document name to a file list, otherwise it closes.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Here's a macro that will list the path and filename of linked pictures in the active document:

    Code:
    Sub ListLinked()
      Dim docIn As Document
      Dim docOut As Document
      Dim fld As Field
      Dim strCode As String
      Dim intPos1 As Integer
      Dim intPos2 As Integer
      Set docIn = ActiveDocument
      Set docOut = Documents.Add
      For Each fld In docIn.Fields
    	If fld.Type = wdFieldIncludePicture Then
    	  strCode = Replace(fld.Code, "\\", "\")
    	  intPos1 = InStr(strCode, Chr(34)) + 1
    	  intPos2 = InStr(intPos1, strCode, Chr(34))
    	  With docOut.Content
    		.InsertAfter Mid(strCode, intPos1, intPos2 - intPos1)
    		.InsertParagraphAfter
    	  End With
    	End If
      Next fld
    End Sub
    I'm not sure what you mean by "selected files", but the above could be expanded to loop through multiple documents.

  3. #3
    New Lounger
    Join Date
    Apr 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, Hans. The selected documents are a range of open files. Actually, the graphics are linked Visio flowcharts.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    What is the field type of linked Visio flowcharts?

  5. #5
    New Lounger
    Join Date
    Apr 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It uses the Link field.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The following version of the macro will loop through all open documents and list the path of all Link fields:

    Code:
    Sub ListLinked()
      Dim docIn As Document
      Dim docOut As Document
      Dim fld As Field
      Dim strCode As String
      Dim intPos1 As Integer
      Dim intPos2 As Integer
      Set docOut = Documents.Add
      For Each docIn In Documents
    	If Not docIn Is docOut Then
    	  For Each fld In docIn.Fields
    		If fld.Type = wdFieldLink Then
    		  strCode = Replace(fld.Code, "\\", "\")
    		  intPos1 = InStr(strCode, Chr(34)) + 1
    		  intPos2 = InStr(intPos1, strCode, Chr(34))
    		  With docOut.Content
    			.InsertAfter Mid(strCode, intPos1, intPos2 - intPos1)
    			.InsertParagraphAfter
    		  End With
    		End If
    	  Next fld
    	End If
      Next docIn
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •