Automating through VBS to run VBA Script

Ananthak275

Board Regular
Joined
Aug 22, 2020
Messages
128
Office Version
  1. 2013
Platform
  1. Windows
  2. MacOS
Hello everyone,

I'm trying to run this VBS script. It should go into the file "Hello.xlsm", Sheet1(in the example, it was module1, i assumed this was referring to the sheet name so i changed it to Sheet1), and "sched" is the name of the macro. it runs but dont show up anything.
set objexcel = CreateObject("Excel.Application")
objExcel.Application.Run "'C:\Hello.xlsm'!Sheet1.sched"
objExcel.DisplayAlerts = False
objExcel.Application.Quit

The macro within "Hello.xlsm"
Sub sched()
MsgBox "hello hello hi hi hi !!!!!"
End Sub
Very simple macro. Not sure what the error is
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Syntax should be like this to run from another workbook
Application.Run "'Another Workbook.xlsm'!NameOfMacro"
 
Upvote 0
Syntax should be like this to run from another workbook
Application.Run "'Another Workbook.xlsm'!NameOfMacro"
I think the code is fine, I think the location of the module may be the issue, assuming that this vbs code is trying to be run outside of excel.
 
Upvote 0
Syntax should be like this to run from another workbook
Application.Run "'Another Workbook.xlsm'!NameOfMacro"
So i got the code to work (see below). But im having a few problems, the file gets locked after if i re run it, do you know why?

set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run "'C:\Users\Documents\Test data\code..xlsm'!sched"
objExcel.Application.Run "'C:\Users\Documents\Test data\code4.xlsm'!sched1"
objExcel.Visible=True

objExcel.DisplayAlerts = False
objExcel.Application.Quit
 
Upvote 0
So i got the code to work (see below). But im having a few problems, the file gets locked after if i re run it, do you know why?
I have created a workbook named code.xlsm with Hello macro you provided above

I run the code below from another workbook again and again with no problem.
Anyway, I noted that you have double dot in workbook name which I remove one code..xlsm. I also remark out the other sched1 macro
VBA Code:
Sub Test()

Set objExcel = CreateObject("Excel.Application")
objExcel.Application.Run "'C:\Users\Documents\Test data\code.xlsm'!sched"
'objExcel.Application.Run "'C:\Users\Documents\Test data\code4.xlsm'!sched1"
objExcel.Visible = True

objExcel.DisplayAlerts = False
objExcel.Application.Quit

End Sub

So, I have no idea why you are having problem
 
Upvote 0
So i got the code to work (see below). But im having a few problems, the file gets locked after if i re run it, do you know why?
try adding the following below your last line:

VBA Code:
Set objExcel = Nothing
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,079
Members
449,094
Latest member
mystic19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top