Share via

Excel Macro Error "Object does not support this action" help

Anonymous
2011-01-18T17:06:30+00:00

I got this code from another excel forum...

Sub App_FileSearch_Example()

Dim OWB As Workbook

With Application.FileSearch

.NewSearch

.LookIn = \\Network\reports\

.Filename = "*.xlsx"

If .Execute(SortBy:=msoSortByLastModified, SortOrder:=msoSortOrderDescending) > 0 Then

For i1 = 1 To .FoundFiles.Count

Set OWB = Workbooks.Open(.FoundFiles(i1))

OWB.Save

OWB.Close

Next i1

End If

End With

End Sub

It gives me the "Object does not support this action" error on the line...

With Application.FileSearch

Does excel 2010 no longer support this?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2011-01-18T17:44:00+00:00

Try this... You will want to swap out the message box at the end with a file open line...

Sub Read_Dir()

Dim ofile As Object

Dim dteMax As Date

Dim oFoundFile As Object

Dim oFold As Object

Dim FSO As Object

Set FSO = CreateObject("scripting.filesystemobject")

'change folder to suit

Set oFold = FSO.GetFolder("H:")

For Each ofile In oFold.Files

With ofile

    If .Type = "Microsoft Excel Worksheet" Then

        If .datelastmodified > dteMax Then

            Set oFoundFile = ofile

            dteMax = .datelastmodified

        End If

    End If

End With

Next ofile

MsgBox oFoundFile.Path

Set FSO = Nothing

End Sub


If this post answers your question, please mark it as the Answer... Jim Thomlinson

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2011-01-18T17:21:13+00:00

    Thank you for the quick response. if i use..

    Sub Read_Dir()

    Dim ofile As Object

    Dim oFold As Object

    Dim FSO As Object

    Set FSO = CreateObject("scripting.filesystemobject")

    'change folder to suit

    Set oFold = FSO.GetFolder("\\Network\reports\")

    For Each ofile In oFold.Files

    Selection.TypeText ofile.Name & vbCrLf

    Next

    Set FSO = Nothing

    End Sub

    how would i modify this to "open" the last modified file,


    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2011-01-18T17:17:56+00:00

    You will need quotes around \\Network\reports\. There may be other issues but that is a start...

    Sub App_FileSearch_Example()

    Dim OWB As Workbook

    With Application.FileSearch

    .NewSearch

    .LookIn = "\\Network\reports\"

    .Filename = "*.xlsx"

    If .Execute(SortBy:=msoSortByLastModified, SortOrder:=msoSortOrderDescending) > 0 Then

    For i1 = 1 To .FoundFiles.Count

    Set OWB = Workbooks.Open(.FoundFiles(i1))

    OWB.Save

    OWB.Close

    Next i1

    End If

    End With

    End Sub


    If this post answers your question, please mark it as the Answer... Jim Thomlinson

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2011-01-18T17:15:24+00:00

    Filesearch is no longer supported

    See this thread

    http://social.answers.microsoft.com/Forums/en-US/officeprog/thread/c5e5c46a-5511-4c39-a4d4-c049cba67af6


    Microsoft® MVP PowerPoint® since 2007.

    Web Page: PowerPoint Alchemy Hints and Tips

    Was this answer helpful?

    0 comments No comments