VBScript calling a macro. From macro, opening a excel, but is grey and no contents are not displayed

Copper Contributor

Hi Team,

 

I am calling a macro from the below vbscript.  Macro has the code to open multiple workbooks and process them.  When executing the macro from Run button, the workbooks are opening fine and the contents are visible. But when calling the macro from  vbscript, the workbooks are opening, but the content section is not visible.

---------

Option Explicit

On Error Resume Next

ExcelMacroExample

Sub ExcelMacroExample()

Dim xlApp
Dim xlBook
Dim WshShell
Dim strCurDir
Dim mergerFile

Set WshShell = CreateObject("WScript.Shell")
strCurDir = WshShell.CurrentDirectory
mergerFile = strCurDir + "\Merge_Function_V1.0.xlsm"

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open(mergerFile)
xlApp.Run "'" & mergerFile & "'!Module1.merge_sheets"
xlBook.Close

Set xlBook = Nothing
Set xlApp = Nothing

End Sub

 

Kindly share your views.

 

Thanks

1 Reply
What do you mean "calling from vbscript"? Do you mean calling from VBA? How are you calling it?

Is that really where On Error Resume Next is located? Outside the Sub? One danger with using On Error Resume Next is that you will bypass errors and never find a command that causes an error, and thus never correct the error.