I am running the same code line son multiple command buttons that open assigned excel templates embedded in the parent spreadsheet.
Private Sub M113_Click()
Dim WDObj As Object
Dim WDApp As Object
Dim str As String
str = ActiveWorkbook.Path & "\CND Scaled Template.xlsm"
Set WDObj = Sheets(2).OLEObjects("CNDS")
WDObj.Verb xlOpen
Dim i As Integer
i = Workbooks.Count
Workbooks(i).SaveCopyAs str
Workbooks(i).Close
Workbooks.Open (str)
Set WDObj = Nothing
Set WDApp = Nothing
End Sub
this is the line where I get error message "Unable to get OLEObjects property of worksheet class"
Set WDObj = Sheets(2).OLEObjects("CNDS")
Running it the first time after opening excel does not give any errors but running it second time is issue. Also going to VBA editor through debug mode and pressing F5 works fine and the entire code executes well. What could be the issue? Also this doesn't happen with Ole objects other than excel.