Hi,
I am confused as to how to call functions from a procedure. My
"ThisWorkbook" code creates new sheets and names them according to cells in a
list on "Original Data" sheet and ten applies a function that shows or hides
pictures depending on cell values. The problem is that the Function
ShowPictures doesn't work. That is, it works on its own if I have the code
in one individual sheet, but I can't seem to make it work on every sheet.
This code is in ThisWorkbook:
Private Sub TEMPLATE_COPY()
Dim cell As Range, Rng As Range
With Worksheets("Original Data")
Set Rng = .Range(.Range("A2:A1000"), .Range("A2:A1000").End(xlDown))
End With
For Each cell In Rng
If cell <> "" Then
Sheets("BBB00161").Copy AFTER:=Sheets(Sheets.Count)
ActiveSheet.Name = cell.Value
ShowPictures ThisWorkbook.Worksheets(ActiveSheet)
End If
Next
End Sub
This code is in Module 1:
ub ShowPictures(sh As Worksheet)
sh.Activate
Dim oPic As Picture
Me.Pictures.Visible = False
With Range("A6")
For Each oPic In Me.Pictures
If oPic.Name = .Text Then
oPic.Visible = True
oPic.Top = .Top
oPic.Left = .Left
Exit For
End If
Next oPic
End With
End Sub
Bookmarks