Implement images in a MS Word document does only work 580 times… please help! RRS feed

  • Question

  • Hi!
    I wrote a markro, which takes images from a folder and puts it in a word document. The makro works like a charm until it comes to the 580th image. Than it ether deletes the image while resizing it or it just not getting it from the folder, instead it puts a square character in. I have no idea what the problem is. Its even more mysterious that the same makro is working under Mac Office 2011. I hope somebody can help! Thank you!
    here is the code I'm using:

    'Insert pictures
      MyFile = Dir$(targetfolder & "\*.*")
            pn = ActiveDocument.InlineShapes.Count
            targetfile = targetfolder & "\" & MyFile
            MyFile = Dir
            With Selection.Find
                .Text = "PICXX"
                .Forward = True
                .Wrap = wdFindContinue
                .MatchWholeWord = True
            End With
            Call clear_clipboard
            Selection.InlineShapes.AddPicture FileName:= _
                    targetfile _
                    , LinkToFile:=False, SaveWithDocument:=True
            ActiveDocument.InlineShapes(pn + 1).Select
            'change size
                With Selection.InlineShapes(1)
                    If AutoScript.FormatBox2.ListIndex = 1 Then
                    .Height = 47.84
                    .Height = 66.05
                    End If
                    .Width = 85.05
                End With
      Loop Until MyFile = ""

    Friday, July 25, 2014 3:37 AM