Communicating with PowerPoint using Excel VBA in Hindi

Buy pdf notes for exams now

Makhanlal Chaturvedi University / BCA / VBA programming

Communicating with PowerPoint using Excel VBA in Hindi

Introduction

PowerPoint और Excel दोनो ही Microsoft Office के बहुत ही पॉपुलर software हैं। अक्सर ऐसा होता है कि हमें Excel में मौजूद data को PowerPoint में present करना होता है, जैसे charts, reports या summaries। इसे manual करने में काफी समय लगता है। लेकिन Excel VBA (Visual Basic for Applications) की मदद से हम PowerPoint को automate कर सकते हैं। इस प्रक्रिया को Excel VBA से PowerPoint Automation कहा जाता है।

1. Communicating with PowerPoint using Excel VBA in Hindi

  • Excel VBA की मदद से हम PowerPoint Application को खोल सकते हैं, नया presentation बना सकते हैं और slides insert कर सकते हैं।
  • PowerPoint को Excel से connect करने के लिए हमें PowerPoint Object Library को enable करना होता है।
  • इसके लिए VBA Editor में जाकर: Tools → References → Microsoft PowerPoint xx.0 Object Library को check करें।
Dim pptApp As PowerPoint.Application Set pptApp = New PowerPoint.Application pptApp.Visible = True

ऊपर दिए गए कोड से हम PowerPoint Application को Excel से खोल सकते हैं और उसे visible बना सकते हैं ताकि user उसे देख सके।

2. Creating PowerPoint slides from Excel VBA in Hindi

  • Slides insert करने के लिए हमें पहले Presentation create करना होता है।
  • उसके बाद उसमें slides add करके title और content भी add कर सकते हैं।
Dim pptPres As PowerPoint.Presentation Set pptPres = pptApp.Presentations.Add Dim slide As PowerPoint.Slide Set slide = pptPres.Slides.Add(1, ppLayoutText) slide.Shapes(1).TextFrame.TextRange.Text = "Excel से PowerPoint Automation" slide.Shapes(2).TextFrame.TextRange.Text = "यह slide Excel VBA द्वारा बनाई गई है।"

यह code एक नया PowerPoint file बनाएगा जिसमें एक slide होगा, और उसमें title व content add कर देगा।

3. Inserting Excel data into PowerPoint slides using VBA in Hindi

  • अगर हमें Excel sheet से data को PowerPoint में डालना है, तो हम cells से values लेकर उन्हें slide पर paste कर सकते हैं।
  • हम data को direct text format में डाल सकते हैं या chart के रूप में भी insert कर सकते हैं।
Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") Dim dataText As String dataText = ws.Range("A1").Value & vbNewLine & ws.Range("A2").Value slide.Shapes(2).TextFrame.TextRange.Text = dataText

इस code से Excel के Sheet1 की A1 और A2 cell की value slide के content में paste हो जाएगी।

Chart को PowerPoint में Paste करना

ws.ChartObjects("Chart 1").Chart.Copy slide.Shapes.Paste

इससे Excel में बना Chart PowerPoint की current slide में paste हो जाएगा।

4. Controlling slide transitions with Excel VBA in Hindi

  • Slide Transition PowerPoint का एक visual effect होता है जो एक slide से दूसरी slide पर जाने पर दिखता है।
  • हम VBA की मदद से transition effect, speed और sound भी control कर सकते हैं।
With slide.SlideShowTransition .EntryEffect = ppEffectFadeSmoothly .Speed = ppTransitionSpeedMedium .AdvanceOnTime = True .AdvanceTime = 5 End With

यह code slide में Fade Smoothly transition apply करेगा और 5 second बाद slide अपने आप change हो जाएगी।

5. Saving presentations through Excel VBA automation in Hindi

  • Automated presentation को save करने के लिए हम VBA में save method का use करते हैं।
  • हम चाहें तो इसे किसी specific folder में किसी नाम से save कर सकते हैं।
pptPres.SaveAs "C:\Users\Public\Documents\MyPresentation.pptx" pptPres.Close pptApp.Quit Set pptApp = Nothing

इस code से हमारी PowerPoint file "MyPresentation.pptx" नाम से save हो जाएगी और PowerPoint application बंद हो जाएगा।

6. Step-by-step Full Example Code

Sub CreatePresentationFromExcel() Dim pptApp As Object Dim pptPres As Object Dim slide As Object Dim ws As Worksheet ' PowerPoint खोलना Set pptApp = CreateObject("PowerPoint.Application") pptApp.Visible = True ' नया प्रेजेंटेशन बनाना Set pptPres = pptApp.Presentations.Add ' Excel Sheet reference Set ws = ThisWorkbook.Sheets("Sheet1") ' Slide 1 बनाना Set slide = pptPres.Slides.Add(1, 1) ' 1 = ppLayoutText slide.Shapes(1).TextFrame.TextRange.Text = "Excel VBA से PowerPoint Automation" slide.Shapes(2).TextFrame.TextRange.Text = "Slide Excel से बनाया गया है।" ' Slide 2 में Excel Data डालना Set slide = pptPres.Slides.Add(2, 1) slide.Shapes(1).TextFrame.TextRange.Text = "Excel Data" slide.Shapes(2).TextFrame.TextRange.Text = ws.Range("A1").Value & vbNewLine & ws.Range("A2").Value ' Slide 3 में Chart डालना Set slide = pptPres.Slides.Add(3, 1) ws.ChartObjects(1).Chart.Copy slide.Shapes.Paste ' Transitions लगाना slide.SlideShowTransition.EntryEffect = 257 ' ppEffectFadeSmoothly slide.SlideShowTransition.AdvanceOnTime = True slide.SlideShowTransition.AdvanceTime = 3 ' Save करना pptPres.SaveAs "C:\Users\Public\Documents\ExcelToPowerPoint.pptx" pptPres.Close pptApp.Quit Set pptApp = Nothing Set pptPres = Nothing Set slide = Nothing Set ws = Nothing End Sub

7. Beginners के लिए आवश्यक सुझाव

  • PowerPoint Automation के लिए सबसे पहले आपको Excel VBA की basic समझ होनी चाहिए।
  • Object Library को enable करना बहुत जरूरी है, वरना PowerPoint के objects काम नहीं करेंगे।
  • Code step-by-step करके चलाएं ताकि errors जल्दी पकड़ में आ सकें।
  • Path सही देना जरूरी है जहां आप अपनी file save करना चाहते हैं।

8. Error Handling Tips

  • PowerPoint Application not found → इसका मतलब system में PowerPoint install नहीं है या VBA में reference नहीं दिया गया।
  • Chart not found → Chart का नाम गलत है या worksheet में chart मौजूद नहीं है।
  • Permission Denied → Save करने के लिए आप जिस folder में file save कर रहे हैं वहां permission नहीं है।

9. PowerPoint VBA Object Hierarchy (Table)

VBA Object Explanation
PowerPoint.Application PowerPoint को launch करने के लिए
Presentation नई presentation बनाने के लिए
Slide एक-एक slide को represent करता है
Shape Text, Chart या Picture को represent करता है

FAQs

Excel को PowerPoint से जोड़ने के लिए सबसे पहले VBA Editor में जाकर "Microsoft PowerPoint xx.0 Object Library" को enable करना होता है। इसके बाद आप PowerPoint Application को create करके उसके अंदर slides बना सकते हैं।
Excel VBA में PowerPoint.Application और PowerPoint.Presentation ऑब्जेक्ट का उपयोग करके नया प्रेजेंटेशन बनाया जाता है, फिर Slides.Add method से नई slides insert की जाती हैं और उसमें text डाला जाता है।
Excel की cell values को VBA के जरिए variable में store करके PowerPoint slide के text placeholders में डाला जा सकता है। इसके अलावा Charts को भी copy-paste करके insert किया जा सकता है।
Slide object की SlideShowTransition property का उपयोग करके transition effect, speed और timing सेट किया जा सकता है जैसे ppEffectFadeSmoothly, AdvanceTime आदि।
SaveAs method का उपयोग करके PowerPoint प्रेजेंटेशन को किसी भी फोल्डर में .pptx फॉर्मेट में सेव किया जा सकता है। Example: pptPres.SaveAs "C:\MyFolder\MyPresentation.pptx"
PowerPoint Object Library Excel VBA को PowerPoint की functionalities access करने की अनुमति देता है। इसके बिना आप PowerPoint-specific objects जैसे Slide, Presentation, Shapes आदि का उपयोग नहीं कर पाएंगे।

Please Give Us Feedback