VBA - PPT equivalent of "thisworkbook" in Excel?

G

Gregg

Steve said:
Note that this may toss errors if access to VB project isn't trusted in
Security settings (or if the file hasn't been saved once)

Of course, with or without Debug.Print, programmatically removing a
module from the VBE causes an error if permission isn't ticked in the
Security settings. Assuming the target file is active, my core code
alone can trigger the error.

Sub RemoveModule()
Dim vbcompX As VBComponent
Set vbcompX = ActivePresentation.VBProject. _
VBComponents("TempMacros")
ActivePresentation.VBProject.V­BComponents.Remove vbcompX
End Sub

Luckily, I can handle that part.
 
G

Gregg

Howard said:
Why?

When you run code, you know the ActiveProject.
So just delete the code in the ActiveProject.

GOT IT!!!

Sub RemoveModule()
Dim vbcompX As VBComponent
Set vbcompX = Application.VBE.ActiveVBProject _
.VBComponents("TempMacros")
Application.VBE.ActiveVBProject.VBComponents _
.Remove vbcompX
End Sub

How does that look? It removes the module no matter what other file is
active. Bingo!

Thanks for pushing me to work it out. <whew!>

-Gregg
 
H

Howard Kaikow

Gregg said:
GOT IT!!!

Sub RemoveModule()
Dim vbcompX As VBComponent
Set vbcompX = Application.VBE.ActiveVBProject _
.VBComponents("TempMacros")
Application.VBE.ActiveVBProject.VBComponents _
.Remove vbcompX
End Sub

How does that look? It removes the module no matter what other file is
active. Bingo!

Haven't played Bingo in years!
Thanks for pushing me to work it out. <whew!>

Folkes doing PPT VBA have the handicap, AFAIK, of there being no PPT VBA
books, so it's harder to grind things out.

However, much of this stuff, in particular, the goal of this thread, is
identically done in Word and Excel VBA.
It pays to look at an Excel VBA book or a Word VBA book to get the basics,

For example, see http://www.standards.cin/index.html?WordVBABooks.
 
G

Gregg

Howard said:
However, much of this stuff, in particular, the goal of this thread, is
identically done in Word and Excel VBA.

Really? You can get...

Sub RemoveModule()
Dim vbcompX As VBComponent
Set vbcompX = Application.VBE.ActiveVBProject _
.VBComponents("TempMacros")
Application.VBE.ActiveVBProject.VBComponents _
.Remove vbcompX
End Sub

.... to run in Excel while another workbook is active?

It errors. But I have a different method I've always used in Excel. And
being different, I don't quite see how it's identical to the PPT
method.

PPT Method:

(above)


Excel Method:

Sub Excel_RemoveModule()
Dim vbcompX As VBComponent
Set vbcompX = ThisWorkbook.VBProject _
.VBComponents("TempMacros")
ThisWorkbook.VBProject.VBComponents _
.Remove vbcompX
End Sub
 
H

Howard Kaikow

Code running in Excel has nothing to do with code running in POT.
Check the books.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top