Enable PowerPoint VBA Reference using VBA

James_Latimer

Active Member
Joined
Jan 20, 2009
Messages
415
Excel 2003

Hello,

I was wondering if anyone knew of a way to enable the powerpoint vba reference using vba coding (regardless of version).

I've had a look around but i cant seem to see anything that enables me to do that.

Many thanks to anyone who can help. cheers.
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056
This code works on 2010 and 2000 you could add the scripts from other versions by going into the editor and click on the Powerpoint reference to find out file location.

Code:
Public Sub AddPPT()
        On Error Resume Next
      Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files (X86)\Microsoft Office\Office14\MSPPT.OLB"
 
       Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Microsoft OfficeXP\Office10\MSPPT.OLB"
    End Sub
 
    End Sub
 

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056
I use the following for scripting runtime in my addin file, you can look up GUID references to find the powerpoint reference that way if the reference is already selected as reference you won't get an error.

Code:
Sub AddRuntimeLibrary()
  On Error Resume Next
  Application.VBE.ActiveVBProject.References.AddFromFile "C:\WINDOWS\system32\scrrun.dll"
Const imgFileName = "PrintIcon"
    Const GUIDRef = "{0002E157-0000-0000-C000-000000000046}"  'MS VBA EXTENSIBILITY 5.3 GUID
    Set PrntIcon = Application.CommandBars.FindControl(ID:=4)
 
    On Error Resume Next  'Ignore Error If Reference Already Established
 
    ThisWorkbook.VBProject.References.AddFromGuid GUIDRef, 5, 3
On Error Resume Next
      Application.VBE.ActiveVBProject.References.AddFromFile "C:\WINDOWS\system32\scrrun.dll"
End Sub
 

James_Latimer

Active Member
Joined
Jan 20, 2009
Messages
415
Thank you so much for looking at this. I apologise but i dont really know much about this! Could you dumb it down for me please?

how do i find out what GUID the powerpoint reference has? what effect will adding in scrrun.dll have? ive had a very quick read as i dont know what scrrun.dll is and its said that this is cpu intensive.

Also what is the reason for adding scrrun.dll twice in the code?

Thanks again and i apologise if im asking stupid questions. i appreciate your help.
 

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056

ADVERTISEMENT

The second code I gave you was one that I use for scripting runtime, it is vital to running many scripts and therefore I have my addin make sure that it is installed, it isn't used for the PPT installation, just an example.

If you google GUID references it gives you the codes so that you can modify the script to be for powerpoint rather than for scripting runtime, you then just change the script to be what you want it to be.

It doesn't install it twice, it checks to see if it is installed and if not then it adds it.

I am logging off now but if I have time later I will look into the reference for it and let you know, if you can't sort it out before then.
 

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056
OK, these scripts will work for 2000 and 2010 not tested on 2003 or 2007.

You can add the script into your workbook open event.


Code:
Sub AddPPT2010()
  On Error Resume Next
  Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files (x86)\Microsoft Office\Office14\MSPPT.OLB"
Const imgFileName = "PrintIcon"
    Const GUIDRef = "{91493440-5A91-11CF-8700-00AA0060263B}"
    Set PrntIcon = Application.CommandBars.FindControl(ID:=4)
 
    On Error Resume Next  'Ignore Error If Reference Already Established
 
    ThisWorkbook.VBProject.References.AddFromGuid GUIDRef, 2, 10
On Error Resume Next
      Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files (x86)\Microsoft Office\Office14\MSPPT.OLB"
Call addPPT2000
End Sub
Sub addPPT2000()
 On Error Resume Next
  Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files (x86)\Microsoft Office\Office14\MSPPT.OLB"
Const imgFileName = "PrintIcon"
    Const GUIDRef = "{91493440-5A91-11CF-8700-00AA0060263B}"
    Set PrntIcon = Application.CommandBars.FindControl(ID:=4)
 
    On Error Resume Next  'Ignore Error If Reference Already Established
 
    ThisWorkbook.VBProject.References.AddFromGuid GUIDRef, 2, 7
On Error Resume Next
      Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files (x86)\Microsoft Office\Office14\MSPPT.OLB"
 
End Sub
 

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,056
I just realised that I didn't modify the 2nd script properly, however it still works.

I had the folder reference wrong.

"C:\Program Files (x86)\Microsoft Office\Office14\MSPPT.OLB"


Code:
Sub addPPT2000()
 On Error Resume Next
  Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Common Files\Microsoft Shared\Office10\MSO.DLL"
Const imgFileName = "PrintIcon"
    Const GUIDRef = "{91493440-5A91-11CF-8700-00AA0060263B}"
    Set PrntIcon = Application.CommandBars.FindControl(ID:=4)
 
    On Error Resume Next  'Ignore Error If Reference Already Established
 
    ThisWorkbook.VBProject.References.AddFromGuid GUIDRef, 2, 7
On Error Resume Next
      Application.VBE.ActiveVBProject.References.AddFromFile "C:\Program Files\Common Files\Microsoft Shared\Office10\MSO.DLL"
 
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,193
Messages
5,594,774
Members
413,934
Latest member
austinb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top