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

%3CLINGO-SUB%20id%3D%22lingo-sub-2316873%22%20slang%3D%22en-US%22%3EVBScript%20calling%20a%20macro.%20From%20macro%2C%20opening%20a%20excel%2C%20but%20is%20grey%20and%20no%20contents%20are%20not%20displayed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2316873%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Team%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20calling%20a%20macro%20from%20the%20below%20vbscript.%26nbsp%3B%20Macro%20has%20the%20code%20to%20open%20multiple%20workbooks%20and%20process%20them.%26nbsp%3B%20When%20executing%20the%20macro%20from%20Run%20button%2C%20the%20workbooks%20are%20opening%20fine%20and%20the%20contents%20are%20visible.%20But%20when%20calling%20the%20macro%20from%26nbsp%3B%20vbscript%2C%20the%20workbooks%20are%20opening%2C%20but%20the%20content%20section%20is%20not%20visible.%3C%2FP%3E%3CP%3E---------%3C%2FP%3E%3CP%3EOption%20Explicit%3C%2FP%3E%3CP%3EOn%20Error%20Resume%20Next%3C%2FP%3E%3CP%3EExcelMacroExample%3C%2FP%3E%3CP%3ESub%20ExcelMacroExample()%3C%2FP%3E%3CP%3EDim%20xlApp%3CBR%20%2F%3EDim%20xlBook%3CBR%20%2F%3EDim%20WshShell%3CBR%20%2F%3EDim%20strCurDir%3CBR%20%2F%3EDim%20mergerFile%3C%2FP%3E%3CP%3ESet%20WshShell%20%3D%20CreateObject(%22WScript.Shell%22)%3CBR%20%2F%3EstrCurDir%20%3D%20WshShell.CurrentDirectory%3CBR%20%2F%3EmergerFile%20%3D%20strCurDir%20%2B%20%22%5CMerge_Function_V1.0.xlsm%22%3C%2FP%3E%3CP%3ESet%20xlApp%20%3D%20CreateObject(%22Excel.Application%22)%3CBR%20%2F%3ExlApp.Visible%20%3D%20True%3CBR%20%2F%3ESet%20xlBook%20%3D%20xlApp.Workbooks.Open(mergerFile)%3CBR%20%2F%3ExlApp.Run%20%22'%22%20%26amp%3B%20mergerFile%20%26amp%3B%20%22'!Module1.merge_sheets%22%3CBR%20%2F%3ExlBook.Close%3C%2FP%3E%3CP%3ESet%20xlBook%20%3D%20Nothing%3CBR%20%2F%3ESet%20xlApp%20%3D%20Nothing%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKindly%20share%20your%20views.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2316873%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2324126%22%20slang%3D%22en-US%22%3ERe%3A%20VBScript%20calling%20a%20macro.%20From%20macro%2C%20opening%20a%20excel%2C%20but%20is%20grey%20and%20no%20contents%20are%20not%20displ%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2324126%22%20slang%3D%22en-US%22%3EWhat%20do%20you%20mean%20%22calling%20from%20vbscript%22%3F%20Do%20you%20mean%20calling%20from%20VBA%3F%20How%20are%20you%20calling%20it%3F%3CBR%20%2F%3E%3CBR%20%2F%3EIs%20that%20really%20where%20On%20Error%20Resume%20Next%20is%20located%3F%20Outside%20the%20Sub%3F%20One%20danger%20with%20using%20On%20Error%20Resume%20Next%20is%20that%20you%20will%20bypass%20errors%20and%20never%20find%20a%20command%20that%20causes%20an%20error%2C%20and%20thus%20never%20correct%20the%20error.%3C%2FLINGO-BODY%3E
Occasional Visitor

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.