Recent File

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andibevan

    Recent File

    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.Applicati on

    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_Fil e()

    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("S cripting.FileSy stemObject")

    Set f = fs.getfolder(fl dr)

    Set f1 = f.Files

    For Each f2 In f1

    If f2.DateLastModi fied > vDT Then

    vFName = f2.Name

    vDT = f2.DateLastModi fied

    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.Ex cel.Workbooks.O pen Val_Open

    'Set xlApp = New Excel.Applicati on

    Set xlApp = Excel.Applicati on

    xlApp.Workbooks .Open(Val_Open)


  • Ken Tucker [MVP]

    #2
    Re: Recent File

    Hi,

    You dont need the set in vb.net

    xlApp = Excel.Applicati on

    Ken
    -------------------------
    "Andibevan" <andibevan@remo ve-to-prevent-spam-hotmail.com> wrote in message
    news:udvpuipZFH A.2420@TK2MSFTN GP12.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.Applicati on

    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_Fil e()

    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("S cripting.FileSy stemObject")

    Set f = fs.getfolder(fl dr)

    Set f1 = f.Files

    For Each f2 In f1

    If f2.DateLastModi fied > vDT Then

    vFName = f2.Name

    vDT = f2.DateLastModi fied

    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.Ex cel.Workbooks.O pen Val_Open

    'Set xlApp = New Excel.Applicati on

    Set xlApp = Excel.Applicati on

    xlApp.Workbooks .Open(Val_Open)



    Comment

    Working...