I have a macro runTest in a PowerPoint file test.pptm that I wish to call by using the following VB script. All works well when the script is called on a machine with Office 2010, but the script will only work with Office 2007 providing the PowerPoint application has been opened before calling the script. I'd be interested to hear whether anyone has experienced a similar problem, or to hear of any potential solutions.
Option Explicit
On Error Resume Next
RunProcess
Sub RunProcess()
Dim pptApp
Dim pptPresentation
Set pptApp = CreateObject("PowerPoint.Application")
Set pptPresentation = pptApp.Presentations.Open("C:\test.pptm", True)
pptApp.Run "test.pptm!runTest"
pptApp.Quit
Set pptPresentation = Nothing
Set pptApp = Nothing
End Sub
I resolved the problem by adding
pptApp.Visible = True
after creating pptApp and before opening the presentation.
In the event that it needs Powerpoint launched, I would just trigger the launch as part of the vbscript
Set WshShell = wscript.CreateObject("wscript.Shell")
WshShell.Run "C:\Program Files (x86)\Microsoft Office\Office12\POWERPNT.EXE"
You could build in some error handling to see which version is installed, and call the appropriate exe file
Related
I am trying to run a VBScript that opens powerpoint and runs a macro named UpdateandBreaklinks. The Script that I am running is as follows:
Dim oApp
Dim oPres
Dim oSlide
Set oApp = CreateObject("Powerpoint.Application")
oApp.visible = true
Set oPres = oApp.Presentations.Open("C:\Users\PPwithLinks.pptm")
Set oSlide = oPres.Slides(1).Duplicate
oApp.Run "PPwithLinks.pptm!UpdateandBreaklinks"
This Gets the script to Run and open Powerpoint, however the Macro is not Ran. I get an error on this line:
oApp.Run "PPwithLinks.pptm!UpdateandBreaklinks"
I have tried to adjust it to this:
oApp.Run "UpdateandBreaklinks"
But I still get the same error. The error reads as:
Application.Run: Invalid request. Sub or funtion not defined.
Code: 80048240
I have researched the problem and all I can find is that people have remedied this same issue with the code above. I am not sure what I am doing incorrectly.
I have further tested the problem and I am now at this point:
So, I created a new pptm, I created a new macro for MsgBox "Hello" within the pptm. When I call the pptm to be opened with VBS, the pptm opens and I still get the error.
BUT, testing further, if I have opened the pptm first and then call the VBS the macro does run.(It opens another instance of the program as a [Read-Only] and runs the macro.)
Also, if I just open the pptm from the VBS(delete the line that runs the macro) and then try to run the Macro manually within PowerPoint then I get the following error: "Because of your security settings, macros have been disabled."
I go into the Macro Security settings and they have not been changed, so it appears to me that when VBS Opens the pptm something is disabling the Macros and therefore erroring out the VBS code to not call and run the macro.
For several years I have been running a compiled VB6 program on an church office computer. I had the vb6 program installed on my home computer (Win 7) This program ran without problems. The program opened Excel spreadsheets and allowed the user to manipulate the data on the spreadsheet.
My Windows 7 computer crashed. I have a Windows 8.1 computer and have loaded vb6 on this computer. The installation appears to be successful except when I run the same visual basic project I get a Runtime Error '-2147319779 Automation Error Library not registered.' A sample of my code is shown below:
Dim oExcel As Excel.Application
Set oExcel = Excel.Application
oExcel.Workbooks.Open ("C:\FPCE Financial\FY-2014\2014-01 Financials.xls")
Application.Visible = True
The error occurs on the "Set oExcel = Excel.Application" line.
Any help would be appreciated.
If you haven't set a reference to Excel you need to use "Late Binding" to create the Excel object. As #Noodles says - if you don't have Office installed, it won't work period.
Try changing this
Dim oExcel As Excel.Application
Set oExcel = Excel.Application
To this
Dim oExcel As Object
Set oExcel = CreateObject("Excel.Application")
Shouldn't you be able to implement the ADOX library via VBScript? The code below runs perfect via Access 2010 on Windows 7, Office 2010 32-bit, but doesn't via a VBScript. Isn't ADOX just another COM Object like say FileSystemObject?
Dim objADOX
Set objADOX = CreateObject("ADOX.Catalog")
objADOX.ActiveConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Zamdrist\Desktop\Work\Scripts\Shell.accdb"
MsgBox objADOX.Tables.Count
Sorry, I should point out, VBScript complains that the provider does not exist. Odd because I do in fact have Access 2010 installed.
This is not meant as an answer just simply as a tip that has helped me tremendously. I am constantly working with providers that only work with 32 bit so i always add the attached code to all of my scripts. This way it doesn't matter if the machine that is executing the code is 32 or 64 bit.
'Check for 64 bit and run as 32 bit if needed.
'On error resume next
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oWs = CreateObject("WScript.Shell")
windowsdir = oWs.ExpandEnvironmentStrings("%windir%")
If InStr(LCase(WScript.FullName), windowsdir & "\system32\") And oFso.FolderExists(windowsdir & "\SysWow64") Then
oWs.Run windowsdir & "\SysWow64\WScript.exe """ & WScript.ScriptFullName & """"
WScript.Quit
End If
'code to run as 32 bit
I have Excel 2003 and 2010 on my machine so when I use set xlapp = new excel.application it creates a new Excel 2003 application. My work around is to create a new Excel 14 application using shell. It works but I need to open an existing excel file to reference the object later.
I would like to reference the object without opening an existing file. Is there any way to reference the new Excel app without using the file name. Below is code for an existing file. Please show me the correct way to do this.
Dim MyApp As Excel.Application
TaskID = Shell("C:\Program Files\Microsoft Office\Office14\EXCEL.EXE "C:\Book2.xlsx", vbNormalFocus)
Set MyApp = GetObject("C:\Book2.xlsx").Application
You can create it ans close Excel ...
strFileName = "c:\test.xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True ' You don't have to use this property....
Set objWorkbook = objExcel.Workbooks.Add()
objWorkbook.SaveAs(strFileName)
objExcel.Quit
Would that work for you? See here original solution: Create an Excel file using vbscripts
The script work on the local computer but not remotely. Any idea?
I'm getting VBScript runtime error "ActiveX component can't create object: XStandard.MD5".
strSource = "C:\WINNT"
Set objFSO = CreateObject(Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strSource)
Set colfiles = objFolder.Files
For each file in colfiles
Set objMD5 = CreateObject("XStandard.MD5")
Go to the DLL folder and use in command prompt > regsrv32 XMD35.dll
http://www.xstandard.com/en/documentation/xmd5/
When you want to instruct a remote computer to instantiate a given ActiveX object, you need to specify the name of the remote server when calling the CreateObject(progID, [serverName]) function.
Otherwise, the script engine attempts to instantiate the object from the local machine.
For example:
Set objMD5 = CreateObject("XStandard.MD5", nameOfYourServer)
And of course, the component must be available on the server.
More info about CreateObject at MSDN
I don't know if it has anything to do with the syntax of line 2. you are missing an open quotation. You have:
Set objFSO = CreateObject(Scripting.FileSystemObject")
You should have:
Set objFSO = CreateObject("Scripting.FileSystemObject")
I realize this is an old question, but google sent me here with the same problem. In my case it was a 32-bit vs 64-bit issue - I needed to use the 32-bit version of CScript to execute.
More details here http://blogs.msdn.com/b/helloworld/archive/2007/12/12/activex-component-can-t-create-object-when-creating-a-32-com-object-in-a-64-bit-machine.aspx
The XStandard.MD5 is a component that is NOT standard in all computers. it is something that needs to be installed. However even after installing you may still run into the same error. This may be because you are running the script in a 64bit system. for some reason the 64bit wscript won't use the xmd5.dll. however you can make a workaround by associating the scriptfiles to run on the 32bit version of wscript. by
going into your default programs. (Windows 8+ Right click the startbutton area [category view] Click Programs, then Default Programs then Associate a file type or protocol with a program) (Windows 7- click on start then click default programs)
Then click vbs then click change program, change it to
C:\Windows\SysWow64\Wscript.exe
NOTE ONLY ON 64BIT
As dmogle says in his comment, you need to make sure that the component is installed on the remote computer. Assuming that you've got access to that computer, download the dll to it and then run the command regsvr32 XMD5.dll as can be seen here.
On another note, your script looks a little funny, the twp last lines are:
For each file in colfiles
Set objMD5 = CreateObject("XStandard.MD5")
Which means that you'll be creating an instance of the MD5 object for each file. I've never used the component in question, but I'm fairly sure that you probably want to create only one instance of the object and then call the functions on that object multiple times. So I'd suggest changing the order of those lines to:
Set objMD5 = CreateObject("XStandard.MD5")
For each file in colfiles