VBA code in Word 2017 will no longer insert picture

Michael Kralik
Michael Kralik used Ask the Experts™
on
Hi Experts,
In the updated Word 2017, my VBA code to insert a picture, which used to work in previous versions, now runs to the point of selecting the picture I want inserted. I select the picture and then receive the error: Run-time error '5382': The graphics filter was unable to convert this file.
Please see the code I was using below. When I ask to debug, it highlights the line of code near the bottom, which is "res = dlg.Show()"
Thanks for you help.

Sub InsertPic1A()
    Dim wrdDoc As Word.Document
    Dim wrdTable1 As Word.Table
    Dim wrdTable2 As Word.Table
    Dim wrdRow1 As Word.Row
    Dim wrdRow1a As Word.Row
    Dim wrdRow2 As Word.Row
    Dim wrdRange As Word.Range
    Dim wrdCell As Word.Cell
    Dim f As Integer
    Dim c As Integer
    Dim wrdField As Word.Field
    Dim wrdFormField1 As Word.FormField
    Dim wrdFormField2 As Word.FormField
    Dim strTitle As String
    Dim strNewTitle As String
    Dim tbl As Table
    'table 1 contains the selection
    Set wrdTable1 = Selection.Tables(1)
    
    Set wrdDoc = ActiveDocument
    Set wrdRow1 = wrdTable1.Rows.Last
    UnLockDoc
    
    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.Delete
    With Selection.Font
        .Name = "Arial"
        .Size = 8
        .Color = wdColorRed
        .Bold = False
        .Italic = False
    End With
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
        "MACROBUTTON InsertPic1B [P]", PreserveFormatting:=False
    
    Set wrdRange = wrdRow1.Range
    'add row and form fields to first table
    Set wrdRow1a = wrdTable1.Rows.Add
   'Move cursor to last cell
    Set tbl = Selection.Tables(1)
   'set focus to last cell in selected table
    Selection.Tables(1).Cell(Selection.Tables(1).Rows.Count, Selection.Tables(1).Columns.Count).Select
    Selection.Collapse (WdCollapseDirection.wdCollapseStart)
    With Selection.Font
        .Name = "Arial"
        .Color = wdColorBlue
        .Size = 8
        .Scaling = 100
    End With
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
        "MACROBUTTON LockComment1 [Lock Entry]", PreserveFormatting:=False

    Selection.MoveLeft Unit:=wdCell
      
    ActiveDocument.Bookmarks.Add "Picture1"
     
    Selection.MoveLeft Unit:=wdCell
    
    With Selection.Font
        .Name = "Arial"
        .Size = 8
        .Color = wdColorBlue
        .Bold = False
        .Italic = False
    End With
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
        "MACROBUTTON RemoveLine [-]", PreserveFormatting:=False
 
 
    Dim dlg As Dialog
    ActiveDocument.Bookmarks("Picture1").Select
    Set dlg = Application.Dialogs(wdDialogInsertPicture)

Dim res As Long
res = dlg.Show()

If res Then
    
   Resize
 
Else

 RemoveLine1
    
End If
    LockDoc
End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
HI,

it seems that you haven't got a full install of Office. Run Office setup again and make sure that you check al the options to be installed on your computer.

Regards

Author

Commented:
Hi... I am using Office 365. I just downloaded the Office suite again and reinstalled. It still has the same issue and halts at the "res = dlg.Show()" line in the code.
Thanks
Top Expert 2016

Commented:
Sorry cannot help further
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

GrahamSkanRetired
Top Expert 2012

Commented:
Does it happen with any picture file?

For the sake of diagnosis, you could try using a new user profile.

Author

Commented:
Hi GramSkan...
This is very confusing for me... I tried a new user and the code worked as it should, resizing and dropping the picture in. So I logged back in to the original user and tried again. I received the same error message. Note, that I tried to select a picture off the main hard drive to insert. As such, I tried again using the original user account, but this time when running the code I selected a picture off of an external hard drive and it inserted the picture correctly. So what do you think is going on?
By the way... it's good to hear from you again. You have helped me with many coding issues over the years and are a wealth of knowledge!

Thanks,
Michael
Retired
Top Expert 2012
Commented:
I don't know precisely, but Word (at least when locally-hosted) caches some data in the registry for speed (a bit like cookies), and sometimes there is a corruption in the data, giving rise to otherwise unexplainable

By design, re-installing does not clear this data. This is so that user settings and preferences are maintained.

This Microsoft article applies to Word versions 2003 to 2106: https://support.microsoft.com/en-us/help/921541/how-to-troubleshoot-problems-that-occur-when-you-start-or-use-word.

There doesn't seem to be an equivalent  for Office 365, but there is a 'Repair' procedure available.  I suggest that you try that.

Author

Commented:
Thank you!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial