Error: 1004 - and Error : 91 - Active X or Macros Issue


I am trying to use an add photo option in an excel sheet. The error reads:

Error: 1004 - The item withe the specified name wasn't found. 

The second error after clicking OK reads:

Error: 91 - Object variable of With block variable not set

After clicking on the OK button 9-10 times, it finds the file I am looking for. The file worked last week and now it doesn't. I did not change any of the coding, but it appears the coding has changed. See the coding listed below. I was told the following in another forum: 

It looks like you've been affected by a problem in a recent Microsoft Update that stops you from creating ActiveX controls. Near the end of your code, it tries to create a button and then refer to it. These are the lines that are triggering the two error messages you get.

You will see the same problem in any file that has this code.

I tried the microsoft fix it tool and it did not fix this problem. Any suggestions or help is greatly appreciated. If I can't fix it, I am going to re-image the computer. 

Private Sub InsertPhoto()
    Dim Count As Integer
    Dim InsertRow As Integer
    Dim TgtRow As Integer
    Dim CmdBtnNbr As Integer
    Dim Loc As Range
    Dim btn As CommandButton
    Dim sObjName As String
    Dim sPassword As String
    Dim RangeAddr As String
    
    On Error GoTo InsertPhoto_Error
    ' Suspend screen updates and unlock the sheet
    Application.ScreenUpdating = False
    sPassword = wksData.Range("$A$4").Value
    wksPhotos.Unprotect Password:=sPassword
    
    'Retrieve the current picture count.
    Count = wksData.Range("PicCount").Value + 1
    If Count > 50 Then
        MsgBox "Maximum photo count met.", vbInformation + vbOKOnly, "MBA Property Inspection Form"
        Application.ScreenUpdating = True
        wksPhotos.Protect Password:=sPassword, DrawingObjects:=True, Contents:=True, Scenarios:=True
        Exit Sub
    End If
    
    ' Select the Catagory dropdown for the last photo. This prevents
    ' Excel 2003 from locking up if a photo is selected.
    '
    If Count > 1 Then
        wksPhotos.Range(apNamePropInspCat & Right("0" & Count - 1, 2)).Select
    End If
    
    'Now get the row where we're going to do our insertion.
    ' We'll insert two rows above the add button
    Set Loc = wksPhotos.cmdAddPic.TopLeftCell
    InsertRow = Loc.Row - 2
    
    'Now compute the cell for our copy destination
    RangeAddr = "B" & InsertRow
    
    ' Copy
    wksResources.Range("nrPhotoBlock").Copy
    wksPhotos.Range(RangeAddr).Insert Shift:=xlDown
    
    ' Add the ActiveX Change Photo button
    TgtRow = InsertRow + apPhotoChgBtnOffset
    sObjName = "CommandButton" & GetBtnNbr(Count)
    wksPhotos.OLEObjects.Add ClassType:="Forms.CommandButton.1"
    Set btn = wksPhotos.OLEObjects(sObjName).Object
    With btn
        .Left = Range("AK" & TgtRow).Left + 1
        .Top = Range("AK" & TgtRow).Top
        .Width = Range("AK" & TgtRow & ":AL" & TgtRow).Width - 2
        .PrintObject = False
        .Caption = "Change Photo " & Count
    End With

January 21st, 2015 1:49pm

Hi,

From your description, the issue might be caused by the Office December 2014 Updates. Please try to see the blog, follow the steps and check if it is helpful:

http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2014/12/13/forms-controls-stop-working-after-december-2014-updates-.aspx

If the above steps not helpful, we might do some code debug, I recommend you post the question to MSDN forum:

http://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev&filter=alltypes&sort=lastpostdesc

The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

George Zhao
TechNet Community Support

Free Windows Admin Tool Kit Click here and download it now
January 22nd, 2015 7:41am

The only way to fix it is to remove the following security update to office. Security Update for Microsoft Office 2010 (KB2553154). I tried each work around and the Microsoft FixIt Tool to no avail. I read online it was a flaw in the update referenced above. When I uninstalled the update, everything regarding excel and active x controls and macro issue. What is amazing to me is that I spent hours with MS on net meetings, etc and they could not fix it. A few quick searches and I found the solution. It truly amazes me that they aren't addressing the issue with a permanent solution. 
March 5th, 2015 4:19pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics