originalusername
New Member
- Joined
- Jan 30, 2019
- Messages
- 3
Good Morning/Afternoon/Evening Everyone,
As you may already have imagined, VBA has kicked my butt to the point where I needed to bother you guys, so apologies for that.
Summary of effort- I have a pre-made Powerpoint template (graduation certificates for students) that has two fields that need filling for every slide made. The fields themselves are formatted as single-cell tables, as I was led to believe that interacts better with Excel code. The first Powerpoint table (“Table 4” per the selection pane) is for student names, and the second (“Table1”) is for the date they graduate.
The issue I’m running into (that isn’t my complete lack of knowledge/understanding on anything VBA) is that the amount certificates we have to make for each class varies by how many students are in each class. The code I’ve been trying to rework is below, courtesy of Worf on a post many moons ago (https://www.mrexcel.com/forum/excel-questions/643780-vba-code-data-powerpoint-table-not-objects.html). Forgive the comments, I was trying to remind/teach myself what it all meant.
The graduation date isn’t accounted for at all in this code, but it would just be copied over and over from one cell. I will make it populate in cell C106 for ease of explanation. Additionally, we would be remaking the certificates with every class, so a "save" function isn't required.
Any assistance/guidance you guys can provide would be greatly appreciated. After reading through some of the posts on this site, I don’t know how much help I can offer in return- most everything seems like super advanced stuff that exceeds my basic use of 'if' statements, but will chip in where I can.
Thank you all in advance!
As you may already have imagined, VBA has kicked my butt to the point where I needed to bother you guys, so apologies for that.
Summary of effort- I have a pre-made Powerpoint template (graduation certificates for students) that has two fields that need filling for every slide made. The fields themselves are formatted as single-cell tables, as I was led to believe that interacts better with Excel code. The first Powerpoint table (“Table 4” per the selection pane) is for student names, and the second (“Table1”) is for the date they graduate.
The issue I’m running into (that isn’t my complete lack of knowledge/understanding on anything VBA) is that the amount certificates we have to make for each class varies by how many students are in each class. The code I’ve been trying to rework is below, courtesy of Worf on a post many moons ago (https://www.mrexcel.com/forum/excel-questions/643780-vba-code-data-powerpoint-table-not-objects.html). Forgive the comments, I was trying to remind/teach myself what it all meant.
Code:
[COLOR=#222222][FONT=Verdana]Sub Attempt_3()[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]'MakingCertificates…hopefully[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]ActiveSheet.Range("$B$108:$J$158").AutoFilterField:=1, Criteria1:="<>"[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]‘Above is the table in question, added this to take away all the potential blank spaces. We don’t have any classes that exceed this many students._
Also, B108:J108 is the header row. The concatenated student names to be copied to the Powerpoint are in the J column, everything else is the _
data that combines in the J column.[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]Dim CMaker1 AsWorksheet, objPPT As Object, nrows%, i%, j%, LastRow%[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]‘I just took this from the original post, don’t really understand what nrows%, i%, or j% are.[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]Set CMaker1 =Worksheets("Input Fields")[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]Set objPPT =CreateObject("PowerPoint.Application")[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]objPPT.Visible= True[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]'Code below is filepath, if the document name changes or is moved, this must change[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]Set objPres =objPPT.presentations.Open(Filepath and PPT name)[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]LastRow =CMaker1.Range("B" & Rows.Count).End(xlUp).Row [/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]'I wanted it to count off the B row after the table was shortened, as it doesn’t contain any functions in it.[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]For b = 108 ToLastRow - 2[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] objPres.Slides(1).Duplicate[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] 'This part also seems to work, duplicates the correct amount of times, but i do not know what the source cell actually is being based off of, im guessing b108[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] 'Update to me: it is off of B108, but B108is the header, so that's neat[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]Next[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]For b = 108 ToLastRow - 1[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] For j= 1 To 1[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] objPres.Slides(j).Shapes("Table4").Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = CMaker1.Cells(i +109, 1).Value[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] 'This part copies cell A109 for reasons unknown, but doesnt loop to keep copying subsequent cells into the remaining slides. [/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana] Next[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]Next[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]Set objPres =Nothing[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]Set objPPT =Nothing[/FONT][/COLOR]
[COLOR=#222222][FONT=Verdana]End Sub[/FONT][/COLOR]
Any assistance/guidance you guys can provide would be greatly appreciated. After reading through some of the posts on this site, I don’t know how much help I can offer in return- most everything seems like super advanced stuff that exceeds my basic use of 'if' statements, but will chip in where I can.
Thank you all in advance!