Have several logo images (similarly sized) inserted on a resources sheet. Need a way for users to easily select which company they want, and have that logo replace the default logo in upper left corner of several sheets.
Want to use a dropdown menu, have used dynamically before with great results. Dropdown can be in a userform or on just out on dashboard sheet. I already looked as stacking logos and trying a z-axis switch but Excel doesn’t seem to support this. I’ve also tried .Replace and .Copy.
Again, logos are already pasted into a resource sheet that gets hidden, so I don’t want users to go hunt down an image directory nor rely on an internet connection to fetch the image (they sometimes work offline). A default image is already emplaced in upper left corners, just need a way to match their (text) company selection to the corresponding logo image/name, and then switch the old logo with new on one several pages that I specify, in the same upper left corner.
Here’s a mishmash of what’s I’ve tried so far, various lines uncommented at various times, and at this point some lines really don’t make sense in the way it’s presented. Only posting for street cred I guess. I’m just trying to get one small feature figured out, not asking anyone to write my program for me (which is a big difference in scope):
Private Sub CompanySelectComboBox_Change() If CompanySelectComboBox.Value <> "Select a company" Then ' select logo here Sheets(Sheets("TaskNew").Index + TaskSheetsComboBox.ListIndex + 1).Activate 'Private Sub TaskSheetsComboBox_Click() 'If TaskSheetsComboBox.Value <> "Go directly to a yellow task sheet" Then ' Sheets(Sheets("TaskNew").Index + TaskSheetsComboBox.ListIndex + 1).Activate 'End If 'End Sub MsgBox CompanySelectComboBox.Value MsgBox CompanySelectComboBox.ListIndex Image("Logo").Replace Image("Logo"), Sheets("Config").Image("Logo2") 'Logo.Select ' another possibility: ' LogoPic.Picture = LoadPicture(Fname) ' another possibility: 'Sheets("Configs").Image("Logo").Copy Before:=Sheets("TaskEnd") ' another possibility: 'CodeNames of Sheets 'Sheets("Configs").Shapes("Picture 1").Copy 'Sheets("Dashboard").Range("A1").PasteSpecial Else ' user didn't select a company, so just keep default (Generic) for now End If End Sub
Well, after your explanation I changed -1 to +1. Let’s break the problem into parts.
First, in your resource sheet, place your pictures in column B. Give each picture a (company name) in column A. You can adjust the row height so each picture fits into it’s own row.
Then this is an example how you associate the names with those pictures:
Dim sh As Worksheet, pic As Shape Set sh = ThisWorkbook.Worksheets("Pictures") For Each pic In sh.Shapes If pic.Type = msoPicture Then Debug.Print pic.TopLeftCell.Cells(1, 0) ' print the company name End If Next
Now, you can create a combo box or user dialog from that, ask the user which company he wants and let him select a name. Here is an example function to copy a picture of a given name to the clipboard:
Function CopyLogoToClipboard(picName As String) As Boolean Dim sh As Worksheet, pic As Shape Set sh = ThisWorkbook.Worksheets("Pictures") For Each pic In sh.Shapes If pic.Type = msoPicture And pic.TopLeftCell.Cells(1, 0) = picName Then pic.Copy CopyLogoToClipboard = True Exit Function End If Next CopyLogoToClipboard = False End Function
(don’t forget to check the return value when you use it).
Now, the last part is to insert the logo to the places where you want it. For example, putting it in the upper left corner on the active sheet:
ActiveSheet.Paste Set pic = Selection.ShapeRange(1) pic.Top = 0 pic.Left = 0
Hope this helps.