-2

In VBA, we have ActivePresentation. I want to know how can we do the same in VB.NET.

I have the following code

Dim oApp As PowerPoint.Application
Dim oPres As PowerPoint.Presentation = oApp.ActivePresentation

My question is how do we declare or use ActivePresentation in VB.NET.

Can anyone help me how we can use ActivePresentation in VB.NET.

Waleed Asif
  • 159
  • 3
  • 15
  • 1
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – reduckted Oct 24 '17 at 11:24
  • My question is actually how do we declare or use ActivePresentation in VB.NET – Waleed Asif Oct 24 '17 at 11:27
  • 1
    Although you edited out the fact that you received a NullReferenceException, that is in fact your problem. See the proposed duplicate. – Blackwood Oct 24 '17 at 13:24
  • You have already correctly declared the ActivePresentation. If, after solving the NullReferenceException. you want a tutorial on how to use ActicePresentation, that would be too broad a question. – Blackwood Oct 24 '17 at 13:26

1 Answers1

2

First you need to declare oApp as New Application, to create a new instance of PowerPoint.
This is required because your code is not ran "inside" PowerPoint like it would be with VBA.

After that you need to open a presentation (or create a new one) which then is available via ActivePresentation.

Dim oApp As New PowerPoint.Application
oApp.Presentations.Open("C:\test.pptx")
Dim oPres As PowerPoint.Presentation = oApp.ActivePresentation

You can also open multiple presentations at the same time, they can be addressed via name:

Dim oPres As PowerPoint.Presentation = oApp.Presentations("test.pptx")

...or index (beginning with 1):

Dim oPres As PowerPoint.Presentation = oApp.Presentations(1)
MatSnow
  • 7,357
  • 3
  • 19
  • 31
  • Exactly, what I was looking for. Many thanks. It worked like a charm. Thanks for the explanation, I was not able to find for active presentation in vb.net. – Waleed Asif Oct 24 '17 at 13:54