Hi all,
New member here. I spent the better part of a day looking for a solution to this, but to no avail. What this is trying to do is extract the modules from VB projects in both an Excel Workbook and PowerPoint presentation to a specified folder. The Excel part already existed as a single subroutine and I had to retool it to the below. It runs fine the first time, but then I noticed PowerPoint would stay in Task Manager after completion. Since an earlier part of the script requires it to be closed, I kill it. However, afterward, I get the following run-time error: "Microsoft VBScript runtime error: The remote server machine does not exist or is unavailable: 'CreateObject'" whenever I try to run it.
According to command prompt, this is occurring at the line "Dim moApp: Set moApp = CreateObject("PowerPoint.Application")". I took a look at the code and just can't figure it out the two questions:
1. Why does PowerPoint linger in Task Manager after the script finishes, but Excel successfully quits?
2. How do I prevent the run-time error from occurring? My hunch is that these two are closely related.
This is the code making the calls to these subroutines:
Any help would be appreciated!
New member here. I spent the better part of a day looking for a solution to this, but to no avail. What this is trying to do is extract the modules from VB projects in both an Excel Workbook and PowerPoint presentation to a specified folder. The Excel part already existed as a single subroutine and I had to retool it to the below. It runs fine the first time, but then I noticed PowerPoint would stay in Task Manager after completion. Since an earlier part of the script requires it to be closed, I kill it. However, afterward, I get the following run-time error: "Microsoft VBScript runtime error: The remote server machine does not exist or is unavailable: 'CreateObject'" whenever I try to run it.
According to command prompt, this is occurring at the line "Dim moApp: Set moApp = CreateObject("PowerPoint.Application")". I took a look at the code and just can't figure it out the two questions:
1. Why does PowerPoint linger in Task Manager after the script finishes, but Excel successfully quits?
2. How do I prevent the run-time error from occurring? My hunch is that these two are closely related.
Code:
Sub ExtractModulesfromPP(sPowerPointPath, sDestinationDir)
Dim moApp: Set moApp = CreateObject("PowerPoint.Application")
moApp.Visible = True
Dim oPP: Set oPP = moApp.Presentations.Open(sPowerPointPath)
Dim bHasPassword: bHasPassword = moApp.ActivePresentation.VBProject.Protection
Call ExtractModules(oPP, sDestinationDir, bHasPassword)
moApp.Quit
End Sub
Sub ExtractModulesfromXL(sWorkbookPath, sDestinationDir)
On Error Resume Next
Dim moApp: Set moApp = CreateObject("Excel.Application")
WScript.Sleep 1500
Dim oWB : Set oWB = moApp.Workbooks.Open(sWorkbookPath)
moApp.DisplayAlerts = False
Dim bHasPassword: bHasPassword = moApp.VBE.ActiveVBProject.VBComponents.Item(1).Properties("HasPassword").Value
Call ExtractModules(moApp, oWB, sDestinationDir, bHasPassword)
moApp.Quit
End Sub
Sub ExtractModules(OffObj, sDestinationDir, bHasPassword)
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
Err.Clear
On Error Resume Next
If Err<>0 then
Wscript.Echo "Cannot export modules."
WScript.Quit(1)
End if
On Error Goto 0
If bHasPassword Then
Wscript.Echo "ERROR: workbook "& offobj.Name & " is password protected. Aborting. Please remove password and re-run"
WScript.Quit(1)
Else
Wscript.Echo " Workbook '"& offobj.Name & "' contains no password: continuing"
If OffObj.VBProject.VBComponents.Count = 0 Then
Wscript.Echo "ERROR: workbook "& offobj.Name & " contains no VB components. Aborting"
WScript.Quit(1)
Else
Wscript.Echo " VB Components found (" & offObj.VBProject.VBComponents.Count & "): continuing"
Dim vbext_ct_ActiveXDesigner: vbext_ct_ActiveXDesigner = 11 ' ActiveX Designer
Dim vbext_ct_ClassModule: vbext_ct_ClassModule = 2 ' Class Module
Dim vbext_ct_Document: vbext_ct_Document = 100 ' Document Module
Dim vbext_ct_MSForm: vbext_ct_MSForm = 3 ' Microsoft Form
Dim vbext_ct_StdModule: vbext_ct_StdModule = 1 ' Standard Module
Dim i: For i = 1 to offObj.VBProject.VBComponents.Count
Select Case offobj.VBProject.VBComponents.Item(i).Type
Case vbext_ct_ActiveXDesigner
Wscript.Echo " Extracting ActiveX Designer: " & OffObj.VBProject.VBComponents.Item(i).Name
OffObj.VBProject.VBComponents.Item(i).Export (sDestinationDir & "\" & OffObj.VBProject.VBComponents.Item(i).Name & ".dsr")
Case vbext_ct_ClassModule
Wscript.Echo " Extracting Class Module: " & offobj.VBProject.VBComponents.Item(i).Name
offobj.VBProject.VBComponents.Item(i).Export (sDestinationDir & "\" & offobj.VBProject.VBComponents.Item(i).Name & ".cls")
Case vbext_ct_MSForm
Wscript.Echo " Extracting Form VBA: " & offobj.VBProject.VBComponents.Item(i).Name
offobj.VBProject.VBComponents.Item(i).Export (sDestinationDir & "\" & offobj.VBProject.VBComponents.Item(i).Name & ".frm")
' Delete the frx file - it's a binary, and thus of no use here, other than to fill up our commit logs
oFSO.DeleteFile(sDestinationDir & "\" & offobj.VBProject.VBComponents.Item(i).Name & ".frx")
Case vbext_ct_StdModule
Wscript.Echo " Extracting Module: " & offobj.VBProject.VBComponents.Item(i).Name
offobj.VBProject.VBComponents.Item(i).Export (sDestinationDir & "\" & offobj.VBProject.VBComponents.Item(i).Name & ".bas")
Case vbext_ct_Document
Wscript.Echo " Extracting Workbook/sheet: " & offobj.VBProject.VBComponents.Item(i).Name
offobj.VBProject.VBComponents.Item(i).Export (sDestinationDir & "\" & offobj.VBProject.VBComponents.Item(i).Name & ".bas")
Case Else
Wscript.Echo "WARNING: Skipping Unknown: " & offobj.VBProject.VBComponents.Item(i).Name & " of type " & offobj.VBProject.VBComponents.Item(i).Type
End Select
Next i
End If
End If
End Sub
Code:
Wscript.echo sNow & ": Extracting modules from Excel"
Dim sAddinWorkbookPath: sAddinWorkbookPath = sResource & "\Files\XLSTART\Addin.xla"
Dim sAddinModulesDestinationDir: sAddinModulesDestinationDir = sResource & "\Modules\Excel Addin"
Call ExtractModulesfromXL(sAddinWorkbookPath, sAddinModulesDestinationDir)
Dim sTemplateWorkbookPath: sTemplateWorkbookPath = Resources & "\Files\Resources\Addin\Templates\Logistics\Model Template.xlt"
Dim sTemplateModulesDestinationDir: sTemplateModulesDestinationDir = sResource & "\Modules\Model Template"
Call ExtractModulesfromXL(sTemplateWorkbookPath, sTemplateModulesDestinationDir)
Wscript.echo sNow & ": Extracting modules from PowerPoint"
WScript.echo ""
Dim sPPCodeDest : sPPCodeDest = sResource & "\Modules\PowerPoint\"
Call ExtractModulesfromPP(sUserPPSourcePath, sPPCodeDest)