I need to use an excel object(which is set in a procedure), to other procedure in the same module . But not able to do it. Please help me doing the same. Below is my code.
Public Sub FirstProc() 'Here the excel object is defined
Set xlApp = CreateObject("Excel.Application")
Set xlWorkbook = xlApp.Workbooks.Open(ReportTemplateDirectory\Test.xlsx")
xlApp.Visible = True
...
... 'all work goes here FINE
...
SecondProc 'calling second proc
End Sub
Below is my second procedure,
Public Sub SecondProc()
' In this procedure i need to delete a sheet of the same excel file which is generated in above procedure.
xlWorkbook.Sheets(4).Delete
End Sub
But I am getting the RunTime Error 424 Object Required. Any help would be appreciated.