Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    What do you want the outcome to be?

  2. #2
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Macro to list out graphic links in text file (MS Word 2003 SP2)

    <P ID="edit" class=small>(Edited by jscher2000 on 24-Oct-08 15:07. Added [pre] and [/pre] around the code block to preserve indenting for easier reading.)</P>Hello,

    I am looking for a macro that will:

    1. Point to a folder full of text files and list out all references to:

    <c>A00510.emf'>

    and

    /Graphics/A00510.emf'>


    The graphic will always start with the letter A but the ending will always be .emf, so I will need to have a wildcard.

    The end result would be a list of graphic links (shown in the format mentioned above).

    Any assistance that can be provided is very much appreciated.

    Note, I had a macro that generated a List of Include Pictures, but this macro is different in that there are no fields in these text files.

    Thanks in advance for assistance provided.

    Jim



    Here was that original macro (for reference purposes):

    <pre>Sub ListOfIncludePicturePaths()
    Dim docExisting As Word.Document, fld As Word.Field, _
    docNew As Word.Document, strTemp() As String
    Set docExisting = ActiveDocument
    With docExisting
    If .Fields.Count > 0 Then
    For Each fld In .Fields
    If fld.Type = wdFieldIncludePicture Then
    If (docNew Is Nothing) Then Set docNew = Documents.Add
    strTemp = Split(fld.Code, """")
    docNew.Content.InsertAfter strTemp(1) & vbCrLf
    End If
    Next
    End If
    End With
    If Not (docNew Is Nothing) Then
    docNew.Activate
    Set docNew = Nothing
    End If
    Set docExisting = Nothing
    End Sub</pre>


  3. #3
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    Hello Hans,

    I am just looking for a Macro that will point to a folder full of .txt files and then list out all the graphic references (e.g. A00510.emf).
    In other words, the macro will create a new document with a running list of all the graphics mentioned in all of the text files.

    The macro I had used in the past did this (thanks to you) through a field code (.e.g INCLUDEPICTURE path), but this time there are no field codes to find.
    I only need the macro to find "A" wildcard ".emf" and create a new document with this running list. Is this possible to do?

    Thanks very much for your assistance.

    Regards,

    -J

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    Does this do what you want?
    <code>
    Sub ListGraphics()
    Dim strPath As String
    Dim strFile As String
    Dim docNew As Document
    Dim docTxt As Document
    With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show Then
    strPath = .SelectedItems(1)
    If Not Right(strPath, 1) = "" Then
    strPath = strPath & ""
    End If
    Else
    MsgBox "You didn't select a folder.", vbExclamation
    Exit Sub
    End If
    End With
    Application.ScreenUpdating = False
    Set docNew = Documents.Add
    strFile = Dir(strPath & "*.txt")
    Do While Not strFile = ""
    Set docTxt = Documents.Open(FileName:=strPath & strFile, _
    AddToRecentFiles:=False, Format:=wdOpenFormatText)
    With docTxt.Content.Find
    .MatchWildcards = True
    .Wrap = wdFindStop
    .Forward = True
    Do While .Execute(FindText:="A*.emf")
    docNew.Content.InsertAfter .Parent.Text & vbCr
    Loop
    End With
    docTxt.Close SaveChanges:=False
    strFile = Dir
    Loop
    Application.ScreenUpdating = True
    End Sub</code>

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    If there are no field codes because the images were embedded, then the original file names probably are not available to VBA. The file names may be in the file's invisible metadata sections, but programmatically this is challenging to extract.

  6. #6
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    Hello all,

    Well the macro did not really work as it listed out many things. In fact, I had to stop it (break the operation) as it was taken too long to process.
    I then ran it on a single text file and it generated 292 pages of data.

    I am working with a .MIF file (from FrameMaker 8), but the MIF file is essentially a text file and you can have a macro go through it, as I did recently (thanks to Hans) and rename graphic anchors.

    Anyway, the screen shot shows exactly what I need to list out (see highlighted text) in a word document. I will then take that list and put it into an Excel spreadsheet for inventory purposes.

    Any assistance on how to specifically list out this line (versus the A, wildcard and .emf) would be very much appreciated. Perhaps searching on that entire line and then printing that line to a file, will be easier
    afterall, than the wildcard approach.

    Thanks in advance for any solutions provided.

    Regards,

    -J
    Attached Images Attached Images

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    You stated that you wanted to list occurrences of A*.emf. Your screenshot shows two occurrences of T*.emf being highlighted. <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  8. #8
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    Okay,
    I see an error that I made in my original post (or forgot to change when I ran the macro - see result of first macro attempt in screen shot). It should have looked for a T wildcard and .emf instead of A wildcard and emf.
    In any event, it might be easier if I can get the macro to list out each and every reference to:


    <ImportObFileDI `<u><u><u><u><c>Graphics<c>T00020.emf'>
    <ImportObFile `../../../../Graphics/T00020.emf'>

    It might be easier to take both of these lines and print them out to file and then continue down until finished.

    Any ideas on how to do this is very much appreciated.

    Thanks in advance.

    -J
    Attached Images Attached Images

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    You didn't mention A+wildcard+.emf only in the original post - you repeated it later on...
    How about this version?
    <code>
    Sub ListGraphics()
    Dim strPath As String
    Dim strFile As String
    Dim docNew As Document
    Dim docTxt As Document
    With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show Then
    strPath = .SelectedItems(1)
    If Not Right(strPath, 1) = "" Then
    strPath = strPath & ""
    End If
    Else
    MsgBox "You didn't select a folder.", vbExclamation
    Exit Sub
    End If
    End With
    Application.ScreenUpdating = False
    Set docNew = Documents.Add
    strFile = Dir(strPath & "*.txt")
    Do While Not strFile = ""
    Set docTxt = Documents.Open(FileName:=strPath & strFile, _
    AddToRecentFiles:=False, Format:=wdOpenFormatText)
    With docTxt.Content.Find
    .MatchWildcards = True
    .Wrap = wdFindStop
    .Forward = True
    Do While .Execute(FindText:="<c>Graphics<c>T*.emf'>")
    docNew.Content.InsertAfter .Parent.Text & vbCr
    Loop
    End With
    With docTxt.Content.Find
    .MatchWildcards = True
    .Wrap = wdFindStop
    .Forward = True
    Do While .Execute(FindText:="/Graphics/T*.emf'>")
    docNew.Content.InsertAfter .Parent.Text & vbCr
    Loop
    End With
    docTxt.Close SaveChanges:=False
    strFile = Dir
    Loop
    Application.ScreenUpdating = True
    End Sub</code>

  10. #10
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    Hello everyone,

    This macro is still not working - probably because of the characters in the graphic name string path.
    So, I simplified it down to "T*.emf" and then the macro created a blank one page document.
    So, then I took the one and only file in my directory, which contains a single graphic called T00050.emf and put that graphic name in the macro code. Next, I ran the macro and it listed out the graphic called: T00050.emf.
    So, it seems that there is a problem with the wildcard picking up the T*.emf name.

    I have attached the screen shot with my modified code.
    Right now, I am just trying to get the macro to open the mif file (which I know MS Word can do) and then display all the wildcard emf graphics.

    Once again, I have kept this simple, by putting a single MIF file into my directory. The MIF file contains a single graphic called: T00050.

    Any reason why the macro cannot read this wildcard?

    Thanks,

    -J
    Attached Images Attached Images

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    Could you attach a zip file with one or two sample .mif files?

  12. #12
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    Hello Hans,

    Here is a copy of a MIF file. I just took a standard generic chapter from FrameMaker and saved it as a mif (after adding in a graphic reference).
    Thanks for the assistance.

    Jim
    Attached Files Attached Files

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    I had gathered from <post:=739,744>post 739,744</post:> that you wanted to look for the word Graphics and something of the form T*.emf in close proximity. But in your sample file this is not the case <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    Here's another attempt:
    <code>
    Sub ListGraphics()
    Dim strPath As String
    Dim strFile As String
    Dim docNew As Document
    Dim docTxt As Document
    With Application.FileDialog(msoFileDialogFolderPicker)
    If .Show Then
    strPath = .SelectedItems(1)
    If Not Right(strPath, 1) = "" Then
    strPath = strPath & ""
    End If
    Else
    MsgBox "You didn't select a folder.", vbExclamation
    Exit Sub
    End If
    End With
    Application.ScreenUpdating = False
    Set docNew = Documents.Add
    strFile = Dir(strPath & "*.mif")
    Do While Not strFile = ""
    Set docTxt = Documents.Open(FileName:=strPath & strFile, _
    AddToRecentFiles:=False, Format:=wdOpenFormatText)
    With docTxt.Content.Find
    .MatchWildcards = True
    .Wrap = wdFindStop
    .Forward = True
    Do While .Execute(FindText:="<!t>[>/]<!/t>T*.emf'>")
    docNew.Content.InsertAfter .Parent.Text & vbCr
    Loop
    End With
    docTxt.Close SaveChanges:=False
    strFile = Dir
    Loop
    Application.ScreenUpdating = True
    End Sub</code>

  14. #14
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    Hello Hans,

    This latest attempt picks up the wildcard format.
    I have a workable script now that will read into a MIF file and list out all the referenced graphics.

    Thank you very, very much.

    Kind regards,

    Jim

  15. #15
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Macro to list out graphic links in text file (MS Word 2003 SP2)

    Hello Hans,

    Do you know how I could modify this macro to check for more than file file extension at the same time?

    For example, I would like to get the macro to check for: T*.emf, T*.png, T*.vsd, T*.bmp and T*.jpg .

    Is it possible for this macro to do that on one pass or does the macro first have to sweep through the directory of files looking for the first graphic file type and then come back and
    hit the other graphic types?

    Thanks once again for your assistance.

    Regards,

    -J

Page 1 of 2 12 LastLast

Posting Permissions

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