Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-21-2021, 09:02 AM
OldGuy1949 OldGuy1949 is offline Excel/VBS DIM MyFSO error Windows 10 Excel/VBS DIM MyFSO error Office 2016
Novice
Excel/VBS DIM MyFSO error
 
Join Date: Apr 2021
Posts: 3
OldGuy1949 is on a distinguished road
Default Excel/VBS DIM MyFSO error

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
Reply With Quote
  #2  
Old 04-21-2021, 09:06 AM
OldGuy1949 OldGuy1949 is offline Excel/VBS DIM MyFSO error Windows 10 Excel/VBS DIM MyFSO error Office 2016
Novice
Excel/VBS DIM MyFSO error
 
Join Date: Apr 2021
Posts: 3
OldGuy1949 is on a distinguished road
Default correction

that should be line 7 instead of 9
Reply With Quote
  #3  
Old 04-26-2021, 03:35 AM
p45cal's Avatar
p45cal p45cal is offline Excel/VBS DIM MyFSO error Windows 10 Excel/VBS DIM MyFSO error Office 2019
Expert
 
Join Date: Apr 2014
Posts: 863
p45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant future
Default

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
but perhaps easier:
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
Reply With Quote
  #4  
Old 04-26-2021, 06:45 AM
OldGuy1949 OldGuy1949 is offline Excel/VBS DIM MyFSO error Windows 10 Excel/VBS DIM MyFSO error Office 2016
Novice
Excel/VBS DIM MyFSO error
 
Join Date: Apr 2021
Posts: 3
OldGuy1949 is on a distinguished road
Default

Understood. Thank you for your help.
Reply With Quote
Reply

Thread Tools
Display Modes


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
Excel/VBS DIM MyFSO error Automation error Unknown error" message once they open the Excel file hlina Excel 1 10-08-2013 09:14 PM
Excel/VBS DIM MyFSO error 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft