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.
Related
I have this simple vbscript, but windows gives me an error when I'm trying to run it. I've never worked with vbscript before and i tried to google, but could figure out why. I'm getting expected end of line error at line 1, character 16. Does anyone see anything?
Also, I'm coding this in notepad and running it by double clicking the file. Is there any other way i should do it?
Dim WithEvents Button As CommandButton
Private Sub Application_StartUp(Cancel As Boolean)
Set Button = CommandButtons.Add("Click me")
End SubPrivate Sub Button_Click()
Msgbox "Clicked", vbInformation
End Sub
Since it was mentioned that notepad is being used for this and looking at the code this certainly appears to be code to add a button to a Form Based application using VBScript in Visual Studio.
VBScript via notepad is not really good at being used for creating GUI dialog boxes and such. A sample code of what would work using Notepad is as such:
toRepeat = InputBox("What should I repeat?", "Echo", "Hello World")
MsgBox toRepeat
Whatever is typed in to the input box will be repeated in this example.
If Visual Studio is not available and there is an interest in building a form based application then it may be possible to create User Forms in VBA via Word or Excel. The following site gives a good tutorial for creating a User Form application in Excel: Excel VBA Userform - Easy Excel Macros
In case there is interest, I recently wrote in to my blog an explanation of the different flavors of VB that are available: VBA vs VBSCRIPT vs Visual Basic
Thanks,
Sean W.
This question may be a little stupid, but i'm curious if it is possible or not.
I have a file named library.xxx(contains vbscript code), which contains predefined functions. And i have an other file test.vbs(also contains vbscript code, just here i use the functions, which are defined in library.xxx). In test.vbs the library is "included", which means, i can use the functions from library.xxx. For example, there is a function called ProgramFiles, and if i call it in test.vbs, i will receive the Program Files folder location.
The problem is, that library.xxx is visible in this way. There is an application called ScriptCryptor. With this application, i can open my library.xxx and make an .exe of it, which would be better for me, since it is not clear text.
My problem is now, how could i execute the command which are called in test.vbs? I think i should read line by line the test.vbs file, and process it somehow. But how? How do i know if the line i read is a function or just a variable? Or both? And how to process them?
Is there some way to do that?
Hopefully it is understandable what i want.
Thanks!
By far the easiest way to accomplish this is to include "library.vbs" in to your "test.vbs" file.
For example:
Library.vbs:
Function ProgramFiles()
ProgramFiles = "C:\Foo"
End Function
test.vbs:
sub includeFile (fSpec)
dim fileSys, file, fileData
set fileSys = createObject ("Scripting.FileSystemObject")
set file = fileSys.openTextFile (fSpec)
fileData = file.readAll ()
file.close
executeGlobal fileData
set file = nothing
set fileSys = nothing
end sub
includeFile "library3.vbs"
wscript.echo ProgramFiles
Your question seems to indicate that you may already be doing this so if you are then I apologize.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
If clear text truly is bothering you then from what I have seen there is no way to make the executable from ScryptCryptor to be made available to your vbscript.
Instead you could create a COM Library DLL to be used as an object in your test.vbs file.
The downside to this is that it will be necessary to learn a new language. Visual Studio Visual Basic certainly is different from Windows Shell Script Visual Basic but it would work for what you want.
Steps to take:
Download Visual Studio 2013 Express for Windows Desktop (or trial version of Ultimate or whatever you feel is appropriate for you)
Open Visual Studio as an Administrator
Create a new Project. Select a "Class Library" under the "Visual Basic" templates
Copy and paste the code below
<ComClass(OurLibrary.ClassId, OurLibrary.InterfaceId, OurLibrary.EventsId)>
Public Class OurLibrary
Private userNameValue As String
Public Const ClassId As String = "40491A82-D53A-46A6-B7E0-1CDF78A33AB6"
Public Const InterfaceId As String = "B49C996C-B039-471D-BF17-0DDA5B3CF517"
Public Const EventsId As String = "6245E3DD-DEB5-4B75-AC03-F4430BC18FDE"
Public Sub New()
MyBase.New()
End Sub
Public Sub mycopy(mySource As String, myDest As String)
My.Computer.FileSystem.CopyFile(mySource, myDest, True)
End Sub
End Class
Click on Project -> ClassLibrary1 Properties
Click on "Compile" and check the box for "Register for COM interop"
Click on Build -> Build Solution
You now have a library that your test.vbs can use:
Set myLib = CreateObject("ClassLibrary1.OurLibrary")
mySource = "C:\mytextfile1.txt"
myDest = "C:\mytextfile2.txt"
myLib.mycopy mySource, myDest
If your like me test.vbs needed to be called as C:\Windows\SysWOW64\cscript.exe test.vbs
For more information about creating COM classes in Visual Basic see here: Walkthrough: Creating COM Objects with Visual Basic
I have VB6 code that executes various Excel macros. I set my breakpoints in VB6 and in the the Excel macro, then begin debugging in the VB6 application. When it reaches (a breakpoint) the statement to execute the macro, it skips over the command and continue traversing through my VB6 code. I was expecting it to jump to Excel and began debugging the Excel macro. Is there some configuration or trick, to debug an Excel macro that is being called from a VB6 application?
When VB6 executes the its own code, it allows the programmer using the IDE to set breakpoints and give control to user when the execution has reached those said breakpoints. However, setting breakpoints in Excel will only benefit you if you (the programmer) have executed the macro from Excel interface. Which is not the case when VB6 is in charge of firing up Excel and telling it to execute the macros within the workbook.
Here is what you can do:
migrate all of the macro code to VB6. It is fairly easy, you just need to add few words here and there like this
'In Excel macro:
Activecell.Offset(0,1).Value = "my value"
so if we want to migrate this line of macro to VB6:
'In VB6 you must declare an instance of EXCEL application:
Dim EX as Excel.Application
EX.Workbooks.Open('c:\my_excel_file.xls')
EX.Sheets(0).Activate 'Go to the first sheet
'Then you are back to business:
EX.ActiveCell.Offset(0,1).Value = "my vlaue"
'But don't forget to close and dispose of EX instance afterwards.
EX.Activeworkbook.Close 'Check save options
EX.Quit
Set EX = Nothing
After you have migrated all of the macros functionality to VB6, you can set breakpoints in VB6 and you will have all the control over the execution and will be able to debug the code as you intended to do.
I am using ruby a WIN32OLE to automate execution of Excel macros with windows scheduler.
I have all of this working properly. My problem comes with having to run a macro embedded in an excel file of an external party (ie I don't have control of the macro). I can call the macro with no problem, however the code contains user prompts (in the form of Msgbox statements)
In short how do I tell the msgbox "yes" or "ok" via WIN32OLE?
What I have tried
Event handling: The Msgbox does not throw a worksheet event. I would have to think that windows throws an event somewhere for the Msgbox (but I am not skilled enough to capture it with WIN32OLE)
-Threading and Sendkeys: I was also unable to get the msgbox to respond to sendkeys. More problematic was that I was unable to get the threading to work with the WIN32OLE object (it worked fine when I was using puts and sleeps to simulate the macro running.)
It appears I am stuck with copying the code into another workbook and removing the msgbox statments, I don't really want to do that because then it will add maintenance work everytime the business logic of the 3rd party code changes.
Here's one way,
install Autoit
and then do:
au3 = WIN32OLE.new("AutoItX3.Control")
au3.ControlClick("MessageBox Title",'', 'OK')
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