Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If an Excel spreadsheet is not found then...
#1
Solved: 10 Years, 9 Months, 1 Week ago
I am working on a function that the initial seeting of a ile bath is set to FaxFilePathName = "Empty". Depending on when a specific Test is run, either the FaxFilePathName variable is not "Empty", if "Empty" call Call CheckingFaxFilePathName () that will set the correct FaxFilePathName. If FaxFilePathName is not found, then exit the itteration as no file was ever created.

I have the main part complete except the line:

Code:
Set objWorkbook = objExcel.WorkBooks.Open(FaxFilePathName)

How can I check if a file exists or if not?

My code:
Code:
If FaxFilePathName = "Empty" Then
        Call CheckingFaxFilePathName ()
        Set objExcel = CreateObject("Excel.application") 'Create a new Microsoft Excel object
        objExcel.Visible = True
        Set objWorkbook = objExcel.WorkBooks.Open(FaxFilePathName)
        Set objDriverSheet = objWorkbook.Worksheets("Sheet1")
        If IsNull(objWorkbook) = True Then
                Reporter.ReportEvent micWarning,"Missing FaxFilePathName" , " The file for 'FaxFilePathName = " & FaxFilePathName & "' and was thus not found. Fax testing was not completed"
                Exit Function
        End If
Else
        Set objExcel = CreateObject("Excel.application") 'Create a new Microsoft Excel object
        objExcel.Visible = True
        Set objWorkbook = objExcel.WorkBooks.Open(FaxFilePathName)
        Set objDriverSheet = objWorkbook.Worksheets("Sheet1")
End If

I think I figured it out: (let me know if this is bad coding)

Code:
Set objExcel = CreateObject("Excel.application") 'Create a new Microsoft Excel object
Set objFso=CreateObject("Scripting.FileSystemObject")
objExcel.Visible = True

If FaxFilePathName = "Empty" Then
        Call CheckingFaxFilePathName ()
                If Not objFso.FileExists(FaxFilePathName)  Then
                Reporter.ReportEvent micWarning,"Missing FaxFilePathName" , " The file for 'FaxFilePathName = " & FaxFilePathName & "' and was thus not found. Fax testing was not completed"
                Exit Function
        End If
End If

Set objWorkbook = objExcel.WorkBooks.Open(FaxFilePathName)
Set objDriverSheet = objWorkbook.Worksheets("Sheet1")
Reply


Messages In This Thread
If an Excel spreadsheet is not found then... - by mv8167 - 03-16-2012, 01:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Object not found during the 2nd iteration of an Action call in a For loop BGunay 0 858 04-23-2020, 07:08 PM
Last Post: BGunay
  Invalid File error importing a spreadsheet but only on a VM msacks 1 2,578 10-19-2014, 09:04 PM
Last Post: supputuri
  How to make QTP take the value of a formula in a spreadsheet? utestqa 1 2,958 07-06-2013, 04:13 PM
Last Post: Ankur
  If Text found mv8167 3 2,643 09-25-2012, 11:24 PM
Last Post: parminderdhiman84
Wink Element not found - VbWindow edj1 4 4,756 02-29-2012, 12:00 AM
Last Post: edj1

Forum Jump:


Users browsing this thread: 1 Guest(s)