VBA PowerPoint - VBA apmācība Powerpoint prezentācijas izveidei

Satura rādītājs

Excel VBA PowerPoint

Izmantojot VBA, mēs varam automatizēt darbu, ko mēs darām PowerPoint, taču vispirms, lai izmantotu VBA kodu vai fragmentus darbam Powerpoint, vispirms izmantojiet PowerPoint drošības opcijas, lai iespējotu visas makro, un pēc tam mēs varam izmantot PowerPoint VBA atsauci makro MS PowerPoint.

VBA skaistums ir tas, ka mēs varam atsaukties uz citiem Microsoft produktiem, piemēram, “Microsoft Word” un “Microsoft PowerPoint”. Mēs parasti izveidojam pārskatus programmā Excel un pēc tam izveidojam PowerPoint prezentācijas. Visi Excel lietotāji parasti tērē daudz laika, lai sagatavotu prezentāciju no Excel datiem un pārskatiem. Ja jūs tērējat daudz laika, gatavojot PowerPoint prezentācijas, šī apmācība parādīs, kā izveidot PowerPoint prezentāciju no pašas Excel, izmantojot VBA kodēšanu.

Iespējot Powerpoint objekta modeli

1. solis: Atveriet VBA redaktoru un pēc tam dodieties uz Rīki un atsauces.

2. solis: Tagad jūs redzēsiet visas atsauces uz VBA projektu. Ritiniet uz leju un atlasiet “Microsoft PowerPoint 15.0 Object Library”.

3. solis: noklikšķiniet uz Labi. Tagad mēs varam piekļūt PowerPoint no Excel.

VBA apmācība PowerPoint prezentācijas izveidei

Mēs varam izveidot PPT divējādi, izmantojot “Early Binding”, bet citā - “Late Binding”. Mēs parādīsim, kā izveidot PowerPoint prezentāciju, izmantojot “Early Binding” tehniku .

Parasti no excel mēs sagatavojam prezentācijas, pamatojoties uz diagrammām un diagrammu interpretāciju. Tāpēc šim nolūkam tajā pašā darblapā esmu izveidojis dažas vienkāršas Excel diagrammas un interpretācijas.

1. darbība: palaidiet VBA apakšprogrammu. Tagad, lai piekļūtu PowerPoint, mēs jau esam iespējojuši PowerPoint objekta modeli iepriekšējās darbībās. Lai piekļūtu tam, mainīgais ir jādeklarē kā PowerPoint. Lietojumprogramma.

Kods:

Sub PPT_Example () Dim PPApp kā PowerPoint. Pieteikuma beigu apakšsadaļa

2. solis: Lai prezentāciju pievienotu PowerPoint, mainīgais ir jādeklarē kā PowerPoint. Prezentācija.

Kods:

 Dim PPPresentation kā PowerPoint. Prezentācija

3. solis: Pēc prezentācijas pievienošanas PowerPoint mums jāpievieno slaids. Lai mainīgo mainītu kā PowerPoint.Slide

Kods:

Dim PPSlide kā PowerPoint. Slide

4. solis: Kad slaids ir pievienots PowerPoint, mums PowerPoint ir jāizmanto formas, ti, tekstlodziņi. Lai mainīgo mainītu kā PowerPoint. Forma

Kods:

Dim PPShape kā PowerPoint. Shape

5. solis: Tagad, lai piekļūtu visām darblapas diagrammām, mainīgais ir jādeklarē kā Excel.ChartObjects.

Kods:

Dim PPCharts kā Excel.ChartObject

Labi, lai sāktu procesu, pietiek ar šiem mainīgajiem.

6. solis: Tagad mums jāpalaiž PowerPoint no Excel. Tā kā tas ir ārējs objekts, mums tas jāiestata kā jauns PowerPoint.

Kods:

Iestatiet PPApp = New PowerPoint. Lietojumprogramma

Tas palaidīs jauno Excel programmu PowerPoint.

7. solis: Tagad mainīgais PPApp ir vienāds ar mūsu uzsākto PowerPoint. Tagad padariet šo PowerPoint redzamu un maksimizējiet logu.

Kods:

PPApp.Visible = msoCTrue PPApp.WindowState = ppWindowMaximized

Šajā brīdī vienkārši palaidiet kodu, izmantojot F5 taustiņu, vai manuāli. Jums vajadzētu redzēt, ka PowerPoint lietotne ir palaista tāpat kā zemāk.

8. solis: Tagad mums ir jāpievieno prezentācija PowerPoint lietotnei, kuru esam palaiduši.

Kods:

Iestatiet PPPresentation = PPApp.Presentations.Add

Tagad mums vajadzētu redzēt šādu PowerPoint prezentāciju.

Step 9: After adding the presentation, we need to add a slide.

Code:

Set PPSlide = PPPresentation.Slides.Add(1, ppLayoutTitleOnly)

Now this will add the title slide like the below.

Step 10: Now we have more than one chart in the worksheet, we need to loop through each chart and paste in the presentation. Below is the code to copy and paste the chart as well as interpretation.

Below is the complete code for you.

Sub PPT_Example() Dim PPApp As PowerPoint.Application Dim PPPresentation As PowerPoint.Presentation Dim PPSlide As PowerPoint.Slide Dim PPShape As PowerPoint.Shape Dim PPCharts As Excel.ChartObject Set PPApp = New PowerPoint.Application PPApp.Visible = msoCTrue PPApp.WindowState = ppWindowMaximized 'Add Presentation Set PPPresentation = PPApp.Presentations.Add 'Loop through each chart in the Excel and paste into the PowerPoint For Each PPCharts In ActiveSheet.ChartObjects PPApp.ActivePresentation.Slides.Add PPApp.ActivePresentation.Slides.Count + 1, ppLayoutText PPApp.ActiveWindow.View.GotoSlide PPApp.ActivePresentation.Slides.Count Set PPSlide = PPApp.ActivePresentation.Slides(PPApp.ActivePresentation.Slides.Count) 'Copy the chart and paste in Powerpoint PPCharts.Select ActiveChart.ChartArea.Copy PPSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select 'Add heading to the slide PPSlide.Shapes(1).TextFrame.TextRange.Text = PPCharts.Chart.ChartTitle.Text 'Allignment of the chart PPApp.ActiveWindow.Selection.ShapeRange.Left = 15 PPApp.ActiveWindow.Selection.ShapeRange.Top = 125 PPSlide.Shapes(2).Width = 200 PPSlide.Shapes(2).Left = 505 'Add interpretation If InStr(PPSlide.Shapes(1).TextFrame.TextRange.Text, "Region") Then PPSlide.Shapes(2).TextFrame.TextRange.Text = Range("K2").Value & vbNewLine PPSlide.Shapes(2).TextFrame.TextRange.InsertAfter (Range("K3").Value & vbNewLine) 'Else if the chart is the "Renewable" consumption chart, then enter the appropriate comments ElseIf InStr(PPSlide.Shapes(1).TextFrame.TextRange.Text, "Month") Then PPSlide.Shapes(2).TextFrame.TextRange.Text = Range("K20").Value & vbNewLine PPSlide.Shapes(2).TextFrame.TextRange.InsertAfter (Range("K21").Value & vbNewLine) PPSlide.Shapes(2).TextFrame.TextRange.InsertAfter (Range("K22").Value & vbNewLine) End If 'Now let's change the font size of the callouts box PPSlide.Shapes(2).TextFrame.TextRange.Font.Size = 16 Next PPCharts End Sub

Interesanti raksti...