title: Scheduling .exe file to run that has excel in the program
body: <p>I have created an app in Visual Studios using VB.NET, upon load the form loads an excel spreadsheet and performs a set of tasks before saving and exiting.</p>
  
  <p>I can manually run the .exe file by clicking but when i schedule it through he built in task scheduler it doesn't do anything. The task doesn't stop or error it just shows as running but never runs </p>
  
  <p>I have done various searching on the net for help with this but i cant seem to find anything anywhere. I have another form that opens a text file, does its thing and then closes the text file and this works perfectly fine which is why it is confusing me so much. I have tried adding my code to the textfile one and copying the commands from the textfile task manager but it doesn't work! I came to the conclusion that it is something to do with excel as the code works fine on its own and the scheduling works fine with a form that links to a text file.</p>
  
  <p>Any help or suggestions are greatly appreciated</p>
  
  <p>Code Below</p>
  
  <pre><code>    Dim filepath1, filepath3, colcontents, rowcontents, txtfile As String
          Dim objExcel, objworkbook As Object
          Dim coln, rown, rowval As Integer
          Dim obj = CreateObject("Scripting.FileSystemObject")
          txtfile = FULLFILEPATH
          filepath1 = FULLFILEPATH
          filepath3 = FULLFILEPATH
          filepath3 = FULLFILEPATH
          'Define as getfile filepath
          Dim objfile = obj.getfile(filepath1)
          If ran = False Then
              objExcel = CreateObject("Excel.Application")
              objExcel.visible = False
              rown = 2
              coln = 1
              colcontents = "Text"
              objworkbook = objExcel.workbooks.open(filepath1)
              objExcel.sheets("KPIStock").activate
              Do Until colcontents = ""
                  colcontents = objExcel.cells(1, coln).text
                  coln = coln + 1
              Loop
              colvalglo = coln
              rown = 1
              rowcontents = "Text"
              'Counts the number of rows that have data in them
              Do Until rowcontents = ""
                  rowcontents = objExcel.cells(rown, 1).text
                  rown = rown + 1
                  rowval = rown
              Loop
              rowvalglo = rowval
              MsgBox("Limits Found")
  If obj.FileExists(filepath4) Then
              'If the file exists then delete it
              obj.DeleteFile(filepath4)
          Else
          End If
          'Pass values to set variables
          colcontents = "Text"
          param1 = Nothing
          param2 = Nothing
          'Define the object as getting a file from the selected filepath
          Dim objfile = obj.getfile(filepath1)
          objExcel = CreateObject("Excel.Application")
          objExcel.visible = False
          'Open selected file
          objworkbook = objExcel.workbooks.open(filepath1)
          colnc = 9
          count = 1
          'Loop until there are no column contents and then save this column number into a global variable
          Do Until colcontents = ""
              rown = 2
              'Activate the Parameteres sheet
              objExcel.sheets("Parameters").activate
              colcontents = objExcel.cells(rown, colnc).text
              'Set Param1 equal to what is contained in the parameters sheet and cells
              param1 = objExcel.cells(rown, colnc).text
              rown = 3
              'Set Param2 equal to what is contained in the parameters sheet and cells
              param2 = objExcel.cells(rown, colnc).text
              objExcel.sheets("KPIStock").activate
              colpaste = colvalglo - 1
              'Header
              rown = 1
              'Save the contents of the cell into the selected Variable
              objExcel.cells(rown, colpaste).value = param1
              'Formula
              rown = 2
              'Save the contents of the cell into the selected Variable
              objExcel.cells(rown, colpaste).value = param2
              'Increase various variables by 1
              colnc = colnc + 1
              colpaste = colpaste + 1
              colvalglo = colvalglo + 1
              count = count + 1
          Loop
          rowvalglo = rowvalglo - 2
          'Copy all of added data and paste to the bottom
          With objExcel
              .range(.cells(2, colvalglo - count), .cells(2, colvalglo)).copy
              .range(.cells(2, colvalglo - count), .cells(rowvalglo, colvalglo)).pastespecial
          End With
          'Set specific cell range to a certain colour
          With objExcel
              .range(.cells(1, colvalglo - count), .cells(1, colvalglo - 65)).Interior.Color = System.Drawing.ColorTranslator.ToOle(Color.LightCyan)
          End With
          'Set specific cell range to a certain colour
          With objExcel
              .range(.cells(2, colvalglo - count), .cells(rowvalglo, colvalglo - 65)).Interior.Color = System.Drawing.ColorTranslator.ToOle(Color.LightYellow)
          End With
          'Set specific cell range to a certain colour
          With objExcel
              .range(.cells(1, colvalglo - 65), .cells(1, colvalglo - 30)).Interior.Color = System.Drawing.ColorTranslator.ToOle(Color.LightGreen)
          End With
          'Set specific cell range to a certain colour
          With objExcel
              .range(.cells(2, colvalglo - 65), .cells(rowvalglo, colvalglo - 30)).Interior.Color = System.Drawing.ColorTranslator.ToOle(Color.LightSalmon)
          End With
          'Set specific cell range to a certain colour
          With objExcel
              .range(.cells(1, colvalglo - 30), .cells(1, colvalglo - 3)).Interior.Color = System.Drawing.ColorTranslator.ToOle(Color.LightSteelBlue)
          End With
          'Set specific cell range to a certain colour
          With objExcel
              .range(.cells(2, colvalglo - 30), .cells(rowvalglo, colvalglo - 3)).Interior.Color = System.Drawing.ColorTranslator.ToOle(Color.GhostWhite)
          End With
          'Copy all of added data and paste as values
          With objExcel
              .range(.cells(2, colvalglo - count), .cells(rowvalglo, colvalglo)).copy
              .range(.cells(2, colvalglo - count), .cells(rowvalglo, colvalglo)).Pastespecial(-4163, -4142, True, False)
          End With
          'Save Output workbook to Filepath4
          objExcel.ActiveWorkbook.SaveAs(filepath4)
          objworkbook.Close
          objExcel.Quit
          objExcel = Nothing
          objworkbook = Nothing
          'Set updated Boolean to TRUE
          updated = True
          rowval = rowval + 1
          'Display message box informating the task has now been complete and to review as required
          MsgBox("Defined columns have now been added, please review")
  </code></pre>