[Solved] Execute .vbs file using macro in Calc

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Locked
Lovepreet323
Posts: 27
Joined: Fri Jun 17, 2022 9:45 am

[Solved] Execute .vbs file using macro in Calc

Post by Lovepreet323 »

Please advise how to run or execute (.vbs) file using calc macro

(.bat) file ruining very well using below code, but (.vbs) file not running
SysShell.Execute(ABC.bat,CmdString,0)
Last edited by Lovepreet323 on Mon Nov 11, 2024 2:31 pm, edited 1 time in total.
OpenOffice 4.0 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11477
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Execute .vbs file using macro in Calc

Post by Zizi64 »

The .bat files requests the operating system only, but - I suppose it - the .vbs files requests some Visual Basic interpreter.

https://stackoverflow.com/questions/690 ... xecute-vbs
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Mr.Dandy
Posts: 461
Joined: Tue Dec 11, 2012 4:22 pm

Re: Execute .vbs file using macro in Calc

Post by Mr.Dandy »

Be sure that soffice process has sufficiant rights to run .vbs script.
Especially if you're running functions on the operating system.
OpenOffice 4.1.12 - Windows 10
Lovepreet323
Posts: 27
Joined: Fri Jun 17, 2022 9:45 am

Re: Execute .vbs file using macro in Calc

Post by Lovepreet323 »

How to give rights to soffice to run .vbs file
OpenOffice 4.0 on Windows 10
User avatar
Mr.Dandy
Posts: 461
Joined: Tue Dec 11, 2012 4:22 pm

Re: Execute .vbs file using macro in Calc

Post by Mr.Dandy »

Lovepreet323 wrote: Thu Nov 07, 2024 8:37 am How to give rights to soffice to run .vbs file
You must launch your VBscript in Elevated mode
Ask to your prefered MS forum

But for me, this is an XY problem. Why using an external program?
OpenOffice 4.1.12 - Windows 10
Lovepreet323
Posts: 27
Joined: Fri Jun 17, 2022 9:45 am

Re: Execute .vbs file using macro in Calc

Post by Lovepreet323 »

I made a vbs script to download a file from web in hidden mode without using any browser. Because i unable hide downloding from browser
OpenOffice 4.0 on Windows 10
ms777
Volunteer
Posts: 207
Joined: Mon Oct 08, 2007 1:33 am

Re: Execute .vbs file using macro in Calc

Post by ms777 »

... if it is just about downloading a file I would recommend to use OOBasic rather than VBS

Code: Select all

oSimpleFileAccess = createUnoService("com.sun.star.ucb.SimpleFileAccess")
oSimpleFileAccess.copy("https://www.google.de", "C:\users\martin\downloads\google.html")
Lovepreet323
Posts: 27
Joined: Fri Jun 17, 2022 9:45 am

Re: Execute .vbs file using macro in Calc

Post by Lovepreet323 »

Please provide complete macro code of above example
OpenOffice 4.0 on Windows 10
User avatar
RoryOF
Moderator
Posts: 35059
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Execute .vbs file using macro in Calc

Post by RoryOF »

For information: many examples of suitable macro code for OpenOffice and LibreOffice, together with an informative discussion on such programming are in the works of Andrew Pitonyak, which may be downloaded free from his site at

https://www.pitonyak.org/oo.php
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
ms777
Volunteer
Posts: 207
Joined: Mon Oct 08, 2007 1:33 am

Re: Execute .vbs file using macro in Calc

Post by ms777 »

This is the complete code. You just have to replace the target web file you want to download and the target storage location
(and add sub main / end sub)
Lovepreet323
Posts: 27
Joined: Fri Jun 17, 2022 9:45 am

Re: Solved **Execute .vbs file using macro in Calc

Post by Lovepreet323 »

Thanks all above who helped me. It's working very well👍
OpenOffice 4.0 on Windows 10
Lovepreet323
Posts: 27
Joined: Fri Jun 17, 2022 9:45 am

Re: [Solved] Execute .vbs file using macro in Calc

Post by Lovepreet323 »

Please help me to solve one more issue to download file in download folder with default or randomly name as file name daliy changed and don't want to change the name of file
Sourepath correctly worked but Destinationpath not working
Sourepath = A1
Destinationpath =B2
oSimpleFileAccess.copy(Sourcepath, Destinationpath)
OpenOffice 4.0 on Windows 10
User avatar
Zizi64
Volunteer
Posts: 11477
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] Execute .vbs file using macro in Calc

Post by Zizi64 »

Please upload your ODF type sample file here. Then we will able to examine the URL/Path syntax. (What string is located in the cells?)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Locked