PDA

View Full Version : FileSystemObject / Microsoft Scripting Runtime in Excel 2010 VBA



Horatio07
11-15-2013, 04:10 AM
Hi,

I'm using a code which makes use of FileSystemObjects. I used to have Excel 2003, but this now switched to Excel 2010- and now the code doesn't work anymore.. For the code to work in 2003, I switched on Microsoft Scripting Runtime via Tools\References in VBA - however, this reference doesn't seem to be available in 2010 anymore. Could you help me out please? Thanks!

I copied my code below for completeness:



'Open the latest transverse views
' !! If the macro doesn't run: open VBA > Tools > References and activate the Microsoft Scripting Runtime !!

Dim FileSys As FileSystemObject
Dim objFile As File
Dim myFolder
Dim strFilename As String
Dim dteFile As Date

'set path for files - change for your folder
Const myDir As String = "Y:\Transverse Views"

'set up filesys objects
Set FileSys = New FileSystemObject
Set myFolder = FileSys.GetFolder(myDir)

'loop through each file and get date last modified. If largest date then store Filename
dteFile = DateSerial(1900, 1, 1)
For Each objFile In myFolder.Files
If Left(objFile.Name, 4) = "Tran" And objFile.DateLastModified > dteFile Then
dteFile = objFile.DateLastModified
strFilename = objFile.Name
End If
Next objFile

Workbooks.Open "Y:\Transverse Views\" & strFilename

JKwan
11-15-2013, 07:59 AM
You may have to hunt it down manually (by using BROWSE), the actual DLL is call SCRRUN.DLL. I would do a search on that file then navigate to that directory, with my system it is located in "C:\Windows\SysWOW64\"

Aflatoon
11-15-2013, 08:01 AM
Asked and answered here: http://www.ozgrid.com/forum/showthread.php?t=184096