title: Excel VBA code to attach files in QC Test Cases
body: <p>I have a tool that capture screenshots of the application that we test at our workplace. Now once I complete my testing of a particular test case or scenarios, we attach the screenshot that we have taken to HP Quality Center manually.</p>
  
  <p>I want to automate this and make my tool to upload the word document to a test in QC Test Lab. Is this possible? If Yes, How can we do this in Excel VBA?</p>
  
  <p>Operations that we need to perform would be as below:</p>
  
  <ol>
  <li>Connect to QC project with login credentials, domain &amp; project details</li>
  <li>Pick a file(s) from a local folder</li>
  <li>Upload a file(s) to QC Test Lab, specific test case</li>
  </ol>
  
  <p>I used the below code, but getting error in that code. I marked it in the code below, please check below :</p>
  
  <pre><code>Dim intTestID, FldPath, TestSetName, i
  Dim TestSetFact, tsTreeMgr, tSetFolder, TestSetsList, theTestSet
  Dim TestSetIdentifier, TSTestFact, TestSetTestsList, testInstanceF, aFilter
  Dim lst, tstInstance
  
  intTestID = "8968"
  
  FldPath = TextBox3.Text '"Root\ProjFold\Release1\BRD"
  TestSetName = ComboBox3.Text '"BRD" '
  
  Set Connection = CreateObject("TDApiOle80.TDConnection")
  Connection.InitConnectionEx Sheet2.Range("B1").Value2
  Connection.Login TextBox1.Text, TextBox2.Text
  Connection.Connect ComboBox1.Text, ComboBox2.Text
  
  Set TestSetFact = Connection.TestSetFactory
  Set tsTreeMgr = Connection.TestSetTreeManager
  
  Set tSetFolder = tsTreeMgr.NodeByPath(FldPath)
  Set TestSetsList = tSetFolder.FindTestSets(TestSetName)
  Set theTestSet = TestSetsList.Item(1)
  TestSetIdentifier = theTestSet.ID
  i = 0
  Set TSTestFact = theTestSet.TSTestFactory
  Set TestSetTestsList = TSTestFact.NewList("")
  
  Set testInstanceF = Connection.TSTestFactory
  Set aFilter = testInstanceF.Filter
  
  aFilter.Filter("TC_TEST_ID") = intTestID
  Set lst = testInstanceF.NewList(aFilter.Text)
  Set tstInstance = lst.Item(1)   &lt;---------------- getting error here
  MsgBox (tstInstance.Field("TS_Name"))
  'tstInstance.Status = "Failed"
  'tstInstance.Field("TC_STATUS") = Item1.Status '"Passed"
  'tstInstance.Post
  Dim RunF, runName, NewRun, runStepF, runlst, Item1, runStep2
  
  MsgBox (tstInstance.Field("TS_Subject"))
  Set RunF = tstInstance.RunFactory
  runName = "Run_" &amp; Month(Date) &amp; "-" &amp; Day(Date) &amp; "_" &amp; Hour(Now) &amp; "-" &amp; Minute(Now) &amp;         "-" &amp; Second(Now)
  Set NewRun = RunF.AddItem(Null)
  NewRun.Status = "Passed"
  NewRun.Name = runName
  NewRun.Post
  NewRun.CopyDesignSteps
  NewRun.Post
  Set runStepF = NewRun.StepFactory
  Set runlst = runStepF.NewList("")
  For Each Item1 In runlst
        Set runStep2 = Item1
        runStep2.Status = "Passed" '
        runStep2.Field("ST_ACTUAL") = "As Expected"
        runStep2.Post
  Next
  'tstInstance.Refresh
  tstInstance.Status = "Failed"
  
  tstInstance.Post
  Connection.DisconnectProject
  Connection.ReleaseConnection
  'Set QC = Nothing
  Set Connection = Nothing
  </code></pre>