Recent File

  • Thread starter Thread starter Andibevan
  • Start date Start date
A

Andibevan

Hi All,

I have written the following code to open the most recent file in a
directory.

It seems to be getting stuck on Set xlApp = Excel.Application

It says the variable is undefined.

Any help would be really appreciated.

Ta

Andi


Option Explicit

'Finds the most recent file in a directory

'Sub Most_Recent_File()

Dim fs, f, f1, f2

'Dim vDT As Date

Dim fldr

'Dim vFName As String

Dim vDT, vFName

Dim Val_RECENT, Val_Open

Dim xlApp

fldr = "S:\SmartMarket\SMV Project Administration\Active Logs\Project Log\"

'fldr = File_Val

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.getfolder(fldr)

Set f1 = f.Files

For Each f2 In f1

If f2.DateLastModified > vDT Then

vFName = f2.Name

vDT = f2.DateLastModified

End If

Next

'Debug.Print vFName, vDT

'If IsMissing(Date_Val) Then

Val_Recent = vFName

'Else

'Val_RECENT = vDT

'End If

'End Sub

Val_Open = fldr & Val_Recent

MsgBox (Val_Open)

'Application.Excel.Workbooks.Open Val_Open

'Set xlApp = New Excel.Application

Set xlApp = Excel.Application

xlApp.Workbooks.Open(Val_Open)
 
Hi,

You dont need the set in vb.net

xlApp = Excel.Application

Ken
-------------------------
Hi All,

I have written the following code to open the most recent file in a
directory.

It seems to be getting stuck on Set xlApp = Excel.Application

It says the variable is undefined.

Any help would be really appreciated.

Ta

Andi


Option Explicit

'Finds the most recent file in a directory

'Sub Most_Recent_File()

Dim fs, f, f1, f2

'Dim vDT As Date

Dim fldr

'Dim vFName As String

Dim vDT, vFName

Dim Val_RECENT, Val_Open

Dim xlApp

fldr = "S:\SmartMarket\SMV Project Administration\Active Logs\Project Log\"

'fldr = File_Val

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.getfolder(fldr)

Set f1 = f.Files

For Each f2 In f1

If f2.DateLastModified > vDT Then

vFName = f2.Name

vDT = f2.DateLastModified

End If

Next

'Debug.Print vFName, vDT

'If IsMissing(Date_Val) Then

Val_Recent = vFName

'Else

'Val_RECENT = vDT

'End If

'End Sub

Val_Open = fldr & Val_Recent

MsgBox (Val_Open)

'Application.Excel.Workbooks.Open Val_Open

'Set xlApp = New Excel.Application

Set xlApp = Excel.Application

xlApp.Workbooks.Open(Val_Open)
 
Back
Top