To loop through all possible values in a DV list, use
Sub TestMacro()
Dim r As Range
Dim v As Variant
Dim i As Integer
'Change B2 to the actual cell
Set r = Worksheets("Forecast Throughput").Range("B2")
v = Split(r.Validation.Formula1, ",")
For i = LBound(v) To UBound(v)
r.Value = v(i)
Application.Calculate
'code to capture screen and place in PPT presentation
Next i
End Sub
Hi Bernie,
Unfortunately, when I plus in that code, it is not looping through the DV list. I may have imported it in the wrong places. Please see below for the full code I am using (I bolded where I entered your code). Thanks!
Sub WorkbooktoPowerPoint()
'Step 1: Declare your variables
Dim pp As Object
Dim PPPres As Object
Dim PPSlide As Object
Dim xlwksht As Worksheet
Dim MyRange1 As String
Dim MyRange2 As String
Dim MyRange3 As String
Dim MyTitle As String
Dim r As Range
Dim v As Variant
Dim i As Integer
Set r = Worksheets("Forecast Throughput").Range("M4")
'Step 2: Open PowerPoint, add a new presentation and make visible
Set pp = CreateObject("PowerPoint.Application")
Set PPPres = pp.Presentations.Add
pp.Visible = True
'Step 3: Set the ranges for your data and title
MyRange1 = "A1:S31" '<<
MyRange2 = "A1:S70"
MyRange3 = "A1:S30"
If Sheets("User Interface").Range("F18") = "YES" Then
v = Split(r.Validation.Formula1, ",")
For i = LBound(v) To UBound(v)
r.Value = v(i)
Application.Calculate
'Step 4: Start the loop through each worksheet
Set xlwksht = ActiveWorkbook.Worksheets("Forecast Throughput")
xlwksht.Select
Application.Wait (Now + TimeValue("0:00:1"))
'Step 5: Copy the range as picture
xlwksht.Range(MyRange1).CopyPicture _
Appearance:=xlScreen, Format:=xlPicture
'Step 6: Count slides and add new blank slide as next available slide number
'(the number 12 represents the enumeration for a Blank Slide)
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, 12)
PPSlide.Select
'Step 7: Paste the picture and adjust its position
PPSlide.Shapes.Paste.Select
pp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
pp.ActiveWindow.Selection.ShapeRange.Top = 30
pp.ActiveWindow.Selection.ShapeRange.Left = 10
pp.ActiveWindow.Selection.ShapeRange.Width = 700
'Step 8: Add the title to the slide then move to next worksheet
Set xlwksht = ActiveWorkbook.Worksheets("Forecast Throughput")
xlwksht.Select
Application.Wait (Now + TimeValue("0:00:1"))
Next i
End If
If Sheets("User Interface").Range("F20") = "YES" Then
'Step 4: Start the loop through each worksheet
Set xlwksht = ActiveWorkbook.Worksheets("Capacity Action List")
xlwksht.Select
Application.Wait (Now + TimeValue("0:00:1"))
'Step 5: Copy the range as picture
xlwksht.Range(MyRange2).CopyPicture _
Appearance:=xlScreen, Format:=xlPicture
'Step 6: Count slides and add new blank slide as next available slide number
'(the number 12 represents the enumeration for a Blank Slide)
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, 12)
PPSlide.Select
'Step 7: Paste the picture and adjust its position
PPSlide.Shapes.Paste.Select
pp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
pp.ActiveWindow.Selection.ShapeRange.Top = 30
pp.ActiveWindow.Selection.ShapeRange.Left = 10
pp.ActiveWindow.Selection.ShapeRange.Width = 700
End If
If Sheets("User Interface").Range("F22") = "YES" Then
'Step 4: Start the loop through each worksheet
Set xlwksht = ActiveWorkbook.Worksheets("Cell Summary")
xlwksht.Select
Application.Wait (Now + TimeValue("0:00:1"))
'Step 5: Copy the range as picture
xlwksht.Range(MyRange3).CopyPicture _
Appearance:=xlScreen, Format:=xlPicture
'Step 6: Count slides and add new blank slide as next available slide number
'(the number 12 represents the enumeration for a Blank Slide)
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, 12)
PPSlide.Select
'Step 7: Paste the picture and adjust its position
PPSlide.Shapes.Paste.Select
pp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
pp.ActiveWindow.Selection.ShapeRange.Top = 30
pp.ActiveWindow.Selection.ShapeRange.Left = 10
pp.ActiveWindow.Selection.ShapeRange.Width = 700
End If
'Step 9: Memory Cleanup
pp.Activate
Set PPSlide = Nothing
Set PPPres = Nothing
Set pp = Nothing
Sheets("User Interface").Select
End Sub