GETOBJECT to know that file existed (1 Viewer)

rickyfong

Registered User.
Local time
Yesterday, 18:55
Joined
Nov 25, 2010
Messages
199
I got the following VBA code, just want to know how to know the file in the GETOBJECT existed! MY idea is to know 1) if the file existed then do the Marco inside the file and 2) if it is not existed then put the file name in a table?? RIght now, when the VBA encountered this GETOBJECT statement, if file not existed, then error message appeared! I have used on error go to , and on error resume , but it is still come up a system error message, telling error 432 of which file not existed!! Please help, thanks a lot!!

Dim appXL As New Excel.Application
Dim appXlBook As Excel.Workbook
Dim appXLQuerySheet As Excel.Worksheet
Dim pathname As String
Dim transfile As String
Dim extension As String
Dim fullpath As String
:
:
:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "DATAExport", "D:\common\invoice\DATAExport.xls", False


If (Forms![tempmasterinput]![Text501] = -1) Then
Set appXlBook = GetObject("C:\COMMON\PRINTTRANS NEW SUM B1.xls")
Else
Set appXlBook = GetObject("C:\COMMON\PRINTTRANS NEW SUM.xls")
End If
:
:
 

Ranman256

Well-known member
Local time
Yesterday, 21:55
Joined
Apr 9, 2015
Messages
4,337
Code:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
if  fso.FileExists("c:\dir\filename.xls) then
    'open file
else
   msgbox "file does not exist"
end if
 

rickyfong

Registered User.
Local time
Yesterday, 18:55
Joined
Nov 25, 2010
Messages
199
GREAT! Thanks a lot!!
 

Users who are viewing this thread

Top Bottom