Hi,
I am confused as to how to call functions from a procedure. My
quot;ThisWorkbookquot; code creates new sheets and names them according to cells in a
list on quot;Original Dataquot; 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(quot;Original Dataquot;)
Set Rng = .Range(.Range(quot;A2:A1000quot;), .Range(quot;A2:A1000quot;).End(xlDown))
End With
For Each cell In Rng
If cell lt;gt; quot;quot; Then
Sheets(quot;BBB00161quot;).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(quot;A6quot;)
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
Sub ShowPictures(sh As Worksheet)
Dim oPic As Picture
sh.Pictures.Visible = False
With sh.Range(quot;A6quot;)
For Each oPic In sh.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--
HTH
Bob Phillips
(remove nothere from email address if mailing direct)
quot;Frankyquot; gt; wrote in message
...
gt; Hi,
gt;
gt; I am confused as to how to call functions from a procedure. My
gt; quot;ThisWorkbookquot; code creates new sheets and names them according to cells
in a
gt; list on quot;Original Dataquot; sheet and ten applies a function that shows or
hides
gt; pictures depending on cell values. The problem is that the Function
gt; ShowPictures doesn't work. That is, it works on its own if I have the
code
gt; in one individual sheet, but I can't seem to make it work on every sheet.
gt; This code is in ThisWorkbook:
gt; Private Sub TEMPLATE_COPY()
gt;
gt; Dim cell As Range, Rng As Range
gt; With Worksheets(quot;Original Dataquot;)
gt; Set Rng = .Range(.Range(quot;A2:A1000quot;),
..Range(quot;A2:A1000quot;).End(xlDown))
gt; End With
gt; For Each cell In Rng
gt; If cell lt;gt; quot;quot; Then
gt; Sheets(quot;BBB00161quot;).Copy AFTER:=Sheets(Sheets.Count)
gt; ActiveSheet.Name = cell.Value
gt; ShowPictures ThisWorkbook.Worksheets(ActiveSheet)
gt; End If
gt; Next
gt; End Sub
gt;
gt; This code is in Module 1:
gt; ub ShowPictures(sh As Worksheet)
gt; sh.Activate
gt; Dim oPic As Picture
gt; Me.Pictures.Visible = False
gt; With Range(quot;A6quot;)
gt; For Each oPic In Me.Pictures
gt; If oPic.Name = .Text Then
gt; oPic.Visible = True
gt; oPic.Top = .Top
gt; oPic.Left = .Left
gt; Exit For
gt; End If
gt; Next oPic
gt; End With
gt; End Sub
gt;
gt;
gt;
Thank you
quot;Bob Phillipsquot; wrote:
gt; Sub ShowPictures(sh As Worksheet)
gt; Dim oPic As Picture
gt; sh.Pictures.Visible = False
gt; With sh.Range(quot;A6quot;)
gt; For Each oPic In sh.Pictures
gt; If oPic.Name = .Text Then
gt; oPic.Visible = True
gt; oPic.Top = .Top
gt; oPic.Left = .Left
gt; Exit For
gt; End If
gt; Next oPic
gt; End With
gt; End Sub
gt;
gt;
gt; --
gt; HTH
gt;
gt; Bob Phillips
gt;
gt; (remove nothere from email address if mailing direct)
gt;
gt; quot;Frankyquot; gt; wrote in message
gt; ...
gt; gt; Hi,
gt; gt;
gt; gt; I am confused as to how to call functions from a procedure. My
gt; gt; quot;ThisWorkbookquot; code creates new sheets and names them according to cells
gt; in a
gt; gt; list on quot;Original Dataquot; sheet and ten applies a function that shows or
gt; hides
gt; gt; pictures depending on cell values. The problem is that the Function
gt; gt; ShowPictures doesn't work. That is, it works on its own if I have the
gt; code
gt; gt; in one individual sheet, but I can't seem to make it work on every sheet.
gt; gt; This code is in ThisWorkbook:
gt; gt; Private Sub TEMPLATE_COPY()
gt; gt;
gt; gt; Dim cell As Range, Rng As Range
gt; gt; With Worksheets(quot;Original Dataquot;)
gt; gt; Set Rng = .Range(.Range(quot;A2:A1000quot;),
gt; ..Range(quot;A2:A1000quot;).End(xlDown))
gt; gt; End With
gt; gt; For Each cell In Rng
gt; gt; If cell lt;gt; quot;quot; Then
gt; gt; Sheets(quot;BBB00161quot;).Copy AFTER:=Sheets(Sheets.Count)
gt; gt; ActiveSheet.Name = cell.Value
gt; gt; ShowPictures ThisWorkbook.Worksheets(ActiveSheet)
gt; gt; End If
gt; gt; Next
gt; gt; End Sub
gt; gt;
gt; gt; This code is in Module 1:
gt; gt; ub ShowPictures(sh As Worksheet)
gt; gt; sh.Activate
gt; gt; Dim oPic As Picture
gt; gt; Me.Pictures.Visible = False
gt; gt; With Range(quot;A6quot;)
gt; gt; For Each oPic In Me.Pictures
gt; gt; If oPic.Name = .Text Then
gt; gt; oPic.Visible = True
gt; gt; oPic.Top = .Top
gt; gt; oPic.Left = .Left
gt; gt; Exit For
gt; gt; End If
gt; gt; Next oPic
gt; gt; End With
gt; gt; End Sub
gt; gt;
gt; gt;
gt; gt;
gt;
gt;
gt;
- Feb 22 Thu 2007 20:35
workbook code
close
全站熱搜
留言列表
發表留言