![]() |
|
|
|
#1
|
|||
|
|||
|
Can someone tell me why I get this error?
It will run from excel/vbs macro but not a standalone from 'Send To' menu. Sub Add_Reference() Application.VBE.ActiveVBProject.References.AddFrom File "C:\Windows\System32\scrrun.dll" 'Add a reference End Sub Sub CheckFileExist() Dim MyFSO As FileSystemObject Set MyFSO = New FileSystemObject If MyFSO.FileExists("C:\temp\text.txt") Then MsgBox "The File Exists" Else MsgBox "The File Does Not Exist" End If End Sub 'error line 9 char 12 ; expected end of statement 'code 800A0401 |
|
#2
|
|||
|
|||
|
that should be line 7 instead of 9
|
|
#3
|
||||
|
||||
|
If this is only for that little macro it's probably not worth adding the reference to the project, use late binding instead:
Code:
Sub CheckFileExist()
Dim MyFSO As Object
Set MyFSO = CreateObject("Scripting.FileSystemObject")
If MyFSO.FileExists("C:\temp\text.txt") Then
MsgBox "The File Exists"
Else
MsgBox "The File Does Not Exist"
End If
End Sub
Code:
Sub CheckFileExist2()
If Dir("C:\temp\text.txt") = "" Then
MsgBox "The File Does Not Exist"
Else
MsgBox "The File Does Exist"
End If
End Sub
|
|
#4
|
|||
|
|||
|
Understood. Thank you for your help.
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Excel runtime error 48; error in loading dll | mwittman5 | Excel Programming | 0 | 01-19-2017 05:18 PM |
| Embeding Excel Docs in Word - Receiving Memory Error Message if Excel is open | kdash | Word | 0 | 05-06-2015 09:38 AM |
| Excel error window: Excel has stopped working | MunganBrus | Excel | 1 | 01-13-2015 11:19 AM |
Automation error Unknown error" message once they open the Excel file
|
hlina | Excel | 1 | 10-08-2013 09:14 PM |
Open Word w Excel & fill Word textboxes w info from Excel fields runtime error 4248
|
Joe Patrick | Word VBA | 2 | 01-30-2012 07:23 AM |