By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,061 Members | 1,539 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,061 IT Pros & Developers. It's quick & easy.

Recent File

P: n/a
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)
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

You dont need the set in vb.net

xlApp = Excel.Application

Ken
-------------------------
"Andibevan" <an*******@remove-to-prevent-spam-hotmail.com> wrote in message
news:ud**************@TK2MSFTNGP12.phx.gbl...
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)

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.