How to open Excel workbook (QTP, VBScript)

Posted by Albert Gareev on Oct 17, 2009 | Categories: How toMS Excel Data

Parent page: Service Functions – Excel (QTP, VBScript)


Check the file exists – Create an instance of Excel by using COM – open (load) file

Dim XLHandle, XLBook

Public Function OpenWorkbook(ByVal sFileName)
 Dim FSO, boolRC

 Set FSO = CreateObject("Scripting.FileSystemObject")
 boolRC = FSO.FileExists(sFileName)
 Set FSO = Nothing
 If Not boolRC Then
  OpenWorkbook = FALSE
  Exit Function
 End If

 Set XLHandle =  CreateObject("Excel.Application")
 XLHandle.DisplayAlerts = False
 Set XLBook = XLHandle.WorkBooks.Open(sFileName)
OpenWorkbook = TRUE

End Function

  • Leave a Reply

    * Required
    ** Your Email is never shared

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.