VBA - PPT equivalent of "thisworkbook" in Excel?

G

Gregg

Howard said:
If all you want to do is remove code in the ActiveVBProject, them all you
need to know is the ActiveVBProject.
You can get the filename fron the ActiveVBProject.

Debug.Print Application.VBE.ActiveVBProject.FileName

More accurately, I want to just capture the file name of the
ActiveVBProject for reference, and then do who knows what with it later
in the code.

I do see that your code string finds the file name running the macro no
matter what other file is active. That's pretty close to what I want.
But how do I reference it in code now? For example, after that line,
how do I make it appear in a msgbox or reference it as the file I want
to activate, or whatever?

Sorry for my ignorance, I've known of it but never used Debug.

Thanks,
Gregg
 
H

Howard Kaikow

Gregg said:
I do see that your code string finds the file name running the macro no
matter what other file is active. That's pretty close to what I want.
But how do I reference it in code now? For example, after that line,
how do I make it appear in a msgbox or reference it as the file I want
to activate, or whatever?

Sorry for my ignorance, I've known of it but never used Debug.

You need to read up on how to use the various objects and their properties
and methods.
 
S

Steve Rindsberg

If all you want to do is remove code in the ActiveVBProject, them all you
need to know is the ActiveVBProject.
You can get the filename fron the ActiveVBProject.

Debug.Print Application.VBE.ActiveVBProject.FileName

Thanks ... very helpful.

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)
 
G

Gregg

You need to read up on how to use the various objects and their properties
and methods.

I know it outputs to the Immediate window, but I can't see how that's
equal in usefulness to the role of the thisworkbook property.

I see now that Google shows several hits where people have asked if
thisworkbook has an equal in PPT, and an equal has never been given. I
think that sums it up for me.

Thanks.
 
G

Gregg

Steve said:
Thanks ... very helpful.

Actually, Steve, you gave that answer to another poster last year.

See...
http://tinyurl.com/dytb2

Typically, I Google things before I ask, but in this case for some
reason I didn't. Had I done so and saw the previous answers, I would
not have asked again. Past discussion pretty much covered it. PPT has
no "thisXXX" property.

Thanks,
Gregg
 
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.
 
S

Steve Rindsberg

Gregg said:
I know it outputs to the Immediate window, but I can't see how that's
equal in usefulness to the role of the thisworkbook property.

Red herring - Debug.Print xxx, MsgBox xxx or whatever, doesn't matter.
It's the stuff after that that counts.
 
S

Steve Rindsberg

Gregg said:
Actually, Steve, you gave that answer to another poster last year.

See...
http://tinyurl.com/dytb2

Geez. Seems I've reached that stage where I've figured out and forgotten more
stuff than I remember. So sad ...

But this does seem to do what you're after, no?
It's not called ThisWhatever but it does appear to return the name of the
presentation the code's running in.
 

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