VBA how to clean Variables

help_for_excel

Board Regular
Joined
Feb 24, 2012
Messages
72
Hi I am writing VBA code to control powertpoint from Excel

my code is
Private ppt_2 As PowerPoint.Presentation

my question is: How to clean\empty PPt_2 variable,

set ppt_2 = nothing, closes power-point file and I don't want to close the file. Is there any other way to clean variable....


please help...thanks in advance
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Are you sure that closes the presentation?

As far as I can see all that will happen is you'll lose the reference and 'clean' the variable.
 
Upvote 0
To be put more precisely I am dealing with two powerpoint file from Excel VBA


Option Explicit

Private pptApp As PowerPoint.Application
Private pptPres1 As PowerPoint.Presentation
Private pptPres2 As PowerPoint.Presentation

Private Sub example()

Set pptApp = New PowerPoint.Application
pptApp.Activate
Set pptPres1 = pptApp.Presentations.Open(Range("XXXX"))
Set pptPres2 = pptApp.Presentations.Open(Range("YYYY"))

pptPres1.Save
pptPres1.Close
Set pptPres1 = Nothing

Set pptPres2 = Nothing 'It closes the 2nd presentation file and cleans the variable. But I dont want to close it, just want to clean the variable. So when I am running Macro without this line of code, it runs fine for the first time. But when macro is run second time it doesn't run, because pptPres2 is not cleaned

pptApp.Quit
Set pptApp = Nothing

End Sub


Can anyone please help....I just want to clean pptPresentation2 variable. Don't want to close the pptPres2 file.
 
Last edited:
Upvote 0
Can I ask how you checked the file was closed when you used that code?

Did you make PowerPoint visible?

That's good way to check what's happening in the application you are automating.

I can check tomorrow but as far as I see it won't close the file.

To close the file you would use the Close method.
Code:
pptPres2.Close

Mind you this would close PowerPoint and all the files open in it.
Code:
pptApp.Quit 
Set pptApp = Nothing
 
Upvote 0
I think I figure it out the way. this code does the trick.



pptPres1.Save
pptPres1.Close
Set pptPres1 = Nothing

Set pptPres2 = Nothing

Set pptApp = Nothing


thank for helping
 
Upvote 0

Forum statistics

Threads
1,223,276
Messages
6,171,138
Members
452,381
Latest member
Nova88

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
Back
Top