PDA

View Full Version : Deleting VBA Code Locks PowerPoint



swsouth
06-05-2006, 03:14 PM
Hi guys, I'm back with another problem I need your gracious help with. I've got a PowerPoint that creates a customized version of itself and saves it as a slideshow. I then need to strip the VBA from the slideshow as a security precaution and also to remove the "Enable Macros" warning that is seen when the file is opened. I've successfully used the code you gave me in an earlier post to remove the macros, but for some reason it only works on my system. I've tested on several other systems ad they lock-up when trying to strip the code. One big difference is I am running dual-procs 3GHz with 2GB of RAM. All other systems tested were single-proc at various speeds and lesser amounts of RAM. Could this be the reason for lock-up? If you would be so kind to review the code and make any suggestions for making it work on other computers it would be so greatly appreciated. In a nutshell, I need to open the slideshow from the parent PowerPoint, strip the code from the slideshow, save the revised version, close it and return to the parent and continue with operations where I left off in the code. Here's what I've got thus far:

Public Sub DeleteAllCode()

Dim sCustName As String
Dim ppApp As Application
Dim ppPres As Presentation
Dim x As Integer

Set ppApp = GetObject(, "PowerPoint.Application")
If Err.Number <> 0 Then 'PowerPoint isn't already running
Set ppApp = New PowerPoint.Application
End If
On Error GoTo 0

sCustName = removeSpaces(TextBox2.Value)

Set ppPres = ppApp.Presentations.Open(CurDir & "\" & sCustName & "\BuyvsRent_" & sCustName & ".pps")


On Error Resume Next
With ActivePresentation.VBProject
For x = .VBComponents.Count To 1 Step -1
.VBComponents.Remove .VBComponents(x)
Next x
For x = .VBComponents.Count To 1 Step -1
.VBComponents(x).CodeModule.DeleteLines _
1, .VBComponents(x).CodeModule.CountOfLines
Next x
End With
On Error GoTo 0

ppApp.ActivePresentation.Save

ppApp.ActivePresentation.Close

End Sub

Thanks so much for any time you can spare,

swsouth

malik641
06-05-2006, 07:13 PM
Cross-post:

http://www.vbforums.com/showthread.php?t=409451