Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If an Excel spreadsheet is not found then...
#1
Solved: 11 Years, 3 Months, 4 Weeks 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
#2
Solved: 11 Years, 3 Months, 4 Weeks ago
Hi,
U can use FSO, it will help u out.

Code:
Set fso=CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(file_location)) Then
    'do something
    else
    'do something    
End If
file_location---> complete path for ur file to open/read

Regards,
Sankalp
Reply
#3
Solved: 11 Years, 3 Months, 4 Weeks ago
Thx Sankalp,

I must have read your mind. I completely forgot about doing this. Thx for confirming the code. ;-)

Have a great weekend.

Lorena
Reply
#4
Solved: 11 Years, 3 Months, 4 Weeks ago
u r welcome..
Reply


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 973 04-23-2020, 07:08 PM
Last Post: BGunay
  Invalid File error importing a spreadsheet but only on a VM msacks 1 2,751 10-19-2014, 09:04 PM
Last Post: supputuri
  How to make QTP take the value of a formula in a spreadsheet? utestqa 1 3,128 07-06-2013, 04:13 PM
Last Post: Ankur
  If Text found mv8167 3 2,792 09-25-2012, 11:24 PM
Last Post: parminderdhiman84
Wink Element not found - VbWindow edj1 4 4,996 02-29-2012, 12:00 AM
Last Post: edj1

Forum Jump:


Users browsing this thread: 1 Guest(s)