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

    It's been a long time since I posted and since that time, I have switched over from MS Word 2003 to MS Word 2007.

    Anyway, I was wondering what I need to do to run Macros in MS Word 2007 (versus MS Word 2003), besides macro security options and the Developer tab.

    I am having trouble running a Macro that will generate a simple list of graphics that brought into a sample document through the "Insert Picture>Insert and Link" option.

    Thanks in advance for the assistance.

    Jim

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Although many Macros will work unchanged, some will need modifications to work correctly, and some may need modifications to work at all.

    When you say "I am having trouble" what actually happens. What do you do and what response do you get from Word?

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

    Ok, well for starters, I created a basic page (e.g. Sample1.docx) with two graphics on the page, that are
    linked to file from a C drive folder. But, I can not get the fieldcodes to toggle for some reason.

    Now, I have learned (in the forum postings) that this can be fixed by saving the document to .DOC format.

    My questions are as follows:

    1. How do I toggle fieldcodes in MS Word 2007? I do not want to save documents back to the .DOC format (if possible). I prefer to use .DOCX now.

    2. Is there a simple macro (that works in MS Word 2007) that will generate a list of INCLUDEPICTURES (Insert Picture > Insert and Link)?

    Thanks in advance for your help.

    Regards,

    Jim

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

    Okay, according to an article on the web. See: http://helpcentral.componentone.com/...s/t/77497.aspx

    The IncludePicture field has been replaced with the InlineShape object.

    The poster of the article references the following code snippet (see below) and that they will now have to completely update
    their macro.

    --------------------------------------------------------------------

    Public Sub test()
    Dim z As Variant
    Dim x As LinkFormat
    Dim y As InlineShape
    Set y = ThisDocument.InlineShapes.Item(1)
    Set x = y.LinkFormat
    z = x.SourceFullName

    End Sub

    ---------------------------------------------------------------------

    Any thoughts on this?

    Thanks,

    -J

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    I am currently running Office 2003, so I can't test this, but the article you referenced certainly sounds credible.

    Do you have a specific existing Macro that you are trying to fix?
    Did you write this yourself or get it from someone else?

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

    Here is the Macro (see below) that will generate a list of graphics that are linked to file. This macro works fine, if the file is in .DOC format.

    But, it DOES NOT WORK when the document is saved as a .DOCX format.

    Does anyone know a way to update this script, so that it will work with the .DOCX format?

    Thanks in advance,

    Jim



    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

  7. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Thanks, your problem is now very clear.

    I don't have a PC running Word 2007 at the moment, so hopefully someone else will jump in and help you now. If not then I will be back in a few days when I have access to a suitably configured PC.

  8. #8
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    [quote name='jamesm067' post='789519' date='18-Aug-2009 08:56']Hello Stuart,

    Here is the Macro (see below) that will generate a list of graphics that are linked to file. This macro works fine, if the file is in .DOC format.

    But, it DOES NOT WORK when the document is saved as a .DOCX format.

    Does anyone know a way to update this script, so that it will work with the .DOCX format?

    Thanks in advance,

    Jim

    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[/quote]
    Jim

    This is interesting:

    In Word 2003, "Insert Picture > Insert and Link" does produce a field.
    In Word 2007 (in a document with one of the new file formats), "Insert Picture > Insert and Link" does not produce a field - you just get an InlineShape, that apparently has a "LinkFormat.SourceFullName" property associated with it.

    Here's some code, which combines your original macro with the code you found - that should work:
    Code:
    Sub ListOfIncludePicturePaths2007()
       
       Dim docExisting As Document
       Dim docNew As Document
       Dim InShape As InlineShape
       Dim strTemp As String
       
       Set docExisting = ActiveDocument
       With docExisting
    	  If .InlineShapes.Count > 0 Then
    		 For Each InShape In docExisting.InlineShapes
    			If (docNew Is Nothing) Then Set docNew = Documents.Add
    			strTemp = InShape.LinkFormat.SourceFullName
    			docNew.Content.InsertAfter strTemp & vbCrLf
    		 Next 'InShape
    	  End If
       End With
       
       If Not (docNew Is Nothing) Then
    	  docNew.Activate
    	  Set docNew = Nothing
       End If
       
       Set docExisting = Nothing
    End Sub
    Gary

Posting Permissions

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