I am looking to merge my scripts to work togheter, my drop-down list (ComboBox) script, to my current script that loads pictures/images into the heading of my Excel sheet.
My script for loading the images looks like this (and works):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myPict As Picture
Dim PictureLoc As String
If Target.Address = Range("A2").Address Then
ActiveSheet.Pictures.Delete
PictureLoc = "K:\Images" & Range("A2").Value & ".png"
With ActiveSheet.PageSetup
.CenterHeaderPicture.Filename = PictureLoc
.CenterHeaderPicture.Height = 25
'.CenterHeaderPicture.Width = 100
.CenterHeader = "&G"
End With
End If
End Sub
My script that updates the ComboBox with the newest pictures from my folder (and this works also):
Private Sub CommandButton1_Click()
Filename = Dir("K:\Images\", vbNormal)
ComboBox1.Clear
Do While Len(Filename) > 0
ComboBox1.AddItem Filename
Filename = Dir()
Loop
End Sub
My problem is getting my first script (loading images into heading) to run with the value/name chosen in the ComboBox. It works perfect for a normal validationg list in Cell A2, but I can't get it to fetch the value in the ComboBox instead of A2. I have tried changing the first part of the script to the following, but it will not fetch the value:
Dim PictureLoc As String
'If Target.Address = Range("A2").Address Then
If Target.Address = ComboBox1.Address Then
ActiveSheet.Pictures.Delete
'PictureLoc = "K:\Images\" & Range("A2").Value & ".jpg"
PictureLoc = "K:\Images\" & ComboBox1.Value '& ".jpg"
With ActiveSheet.PageSetup
.CenterHeaderPicture.Filename = PictureLoc
.CenterHeaderPicture.Height = 25
'.CenterHeaderPicture.Width = 100
.CenterHeader = "&G"
End With
End If
End Sub
Any suggestions?