Application.FileSearch Error

crex27

New Member
Joined
Dec 24, 2013
Messages
1
Hi Guys,
I am not good with VBA.
Recently all are sytems are migrated from WIN XP to Win7.
Since then whenever we run a specific macro we get an error.
Can somebody help me fix the code..


PFB the code :

Option Explicit
Dim fd As FileDialog ' 'Declare a variable as a FileDialog object.
Dim varSelectedItem As Variant ' Path of folder
Dim wb As Workbook
Dim ws As Worksheet
Sub ImportData()

Dim i As Integer
Application.Calculation = xlCalculationManual
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
'Use a With...End With block to reference the FileDialog object.
With fd
'Use the Show method to display the File Picker dialog box
'The user pressed the action button.
If .Show = True Then
.Title = "Select a Folder"
.AllowMultiSelect = False
varSelectedItem = .SelectedItems(1)
Else
MsgBox "Cancelled", vbApplicationModal, "Select Folder"
End If
End With
'************************************
With Application.FileSearch
.NewSearch
.LookIn = varSelectedItem
.SearchSubFolders = False
.Filename = "*.xls"
.Execute
For i = 1 To .FoundFiles.Count
'Open each workbook
Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
'Perform the operation on the open workbook
wb.Worksheets("sheet1").Cells.Select
Selection.Copy
ThisWorkbook.Sheets("Dump").Activate
ThisWorkbook.Sheets("Dump").Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Call Macro14
'close the workbook
wb.Close
'On to the next workbook
Next i
End With
'**************************************
'Set the object variable to Nothing.
Set fd = Nothing
For Each ws In Worksheets
ws.Calculate
Next ws
Application.Calculation = xlCalculationAutomatic
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
It has nothing to do with the operating system but everything with your office version. Filesearch has been removed since office 2007.

Please wrap VBA code in code tags

To retrieve all xls files in directory G:\OF you can use:

Code:
Sub M_snb()
  c00="G:\OF\"
  c01 ="xls"
  sn=split(createobject("wscript.shell").exec("cmd /c Dir """ & c00 & "*." & c01 &""" /b").stdout.readall),vbcrlf)

  for j=0 to ubound(sn)
    with getobject(iif(instr(sn(j),":"),"",c00) & sn(j)
' perform the copy operations
      .close true
    end with
  next
End Sub
 
Last edited:
Upvote 0
It has nothing to do with the operating system but everything with your office version. Filesearch has been removed since office 2007.

Please wrap VBA code in code tags

Oops this is correct. Too late to edit my post but it should read "That functionality has been removed in office 2007+"
 
Upvote 0
Amended code
Code:
Sub M_snb()
  c00="G:\OF\"
  c01 ="xls"
  sn=split(createobject("wscript.shell").exec("cmd /c Dir """ & c00 & "*." & c01 &""" /b").stdout.readall,vbcrlf)

  for j=0 to ubound(sn)
    with getobject(iif(instr(sn(j),":"),"",c00) & sn(j))
 '  perform the copy operations
      .close true
    end with
  next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top