Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed! - Replace image in xls containing VBA 1

Status
Not open for further replies.

MSIsam

Programmer
Sep 29, 2003
173
US
I have an existing Excel file that was created by a former employee (i.e. no longer supported) to create reports and download to user desktops. We have had a request to change the logo at the top of the spreadsheet and have had dificulty doing so. I do not know VBA but would like to know if there is a simple fix to the code that would allow this change. As a temporaty solution, we have just placed the new logo over the top of the old, but since we do not know exactly what the code is doing, we would like to know how to remove the old one completely and link the new one to the code. Here is the code that the error occurs on when the old logo (Icon?) is removed. Error is highlighted in bold red.
Code:
Private Sub Show(strObj As String, intLen As Integer)
  Dim intShapes As Integer
  
  With shtMenu
    .Unprotect gkstrPW
    Application.ScreenUpdating = False
    'hide and show shapes
    For intShapes = 1 To .Shapes.Count
      If Right(.Shapes(intShapes).Name, intLen) = strObj And Left(.Shapes(intShapes).Name, 3) <> "box" Then
        .Shapes(intShapes).Visible = True
      ElseIf Left(.Shapes(intShapes).Name, 3) <> "box" And Left(.Shapes(intShapes).Name, 3) <> "frm" Then
        .Shapes(intShapes).Visible = False
      ElseIf Right(.Shapes(intShapes).Name, intLen) = strObj And Left(.Shapes(intShapes).Name, 3) = "box" Then
        .Shapes(intShapes).Fill.ForeColor.RGB = RGB(0, 152, 148)
        .Shapes(intShapes).Select
        Selection.Characters.Font.ColorIndex = 2
        .Cells(1, 1).Select
      ElseIf Right(.Shapes(intShapes).Name, intLen) <> strObj And Left(.Shapes(intShapes).Name, 3) = "box" Then
        .Shapes(intShapes).Fill.ForeColor.RGB = RGB(229, 205, 228)
        .Shapes(intShapes).Select
        Selection.Characters.Font.ColorIndex = 14
        .Cells(1, 1).Select
      End If
    Next intShapes
      
    'hide date dropdowns
    .Shapes("txbDownload").Visible = False
    .Shapes("recDownload").Visible = False
    .Shapes("ddbDayDownload").Visible = False
    .Shapes("ddbMonthDownload").Visible = False
    .Shapes("ddbYearDownload").Visible = False
    .Shapes("arwDownload").Visible = False
      
   
   'make sure everything else is in visible
    .Shapes("BtnHelp").Visible = True
 [b][COLOR=red] .Shapes("Icon").Visible = True [/color][/b]
    
    .Protect gkstrPW
    Application.ScreenUpdating = False
  End With
End Sub

Error Message:
Code:
Run-time error '-2147024809 (80070057)':
The item with the specified name wasn't found

Thanks in advance for any help,
Sam
 
This is just a quick fix but you need to name the new logo "Icon"

Since this is a one-shot deal I would open a blank worksheet, put the new logo in it and run this code

Sub nameshape()

ActiveSheet.Shapes(1).Name = "Icon"
End Sub

Then delete the old logo from your form, copy the new logo from the worksheet to the form and save the change. The new logo should now be named "Icon" which should prevent the code from throwing that error.
 
I just tried your solution and it worked great. Thank you so much!

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top