Plz Help

Shariq.khan

New Member
Joined
Jun 16, 2011
Messages
5
Hi! I want to Create a Blank Workbook using VB. But I've a problem with following Code:
I'm getting and Error: i.e. Object Required on the Line
With Application.FileSearch.
Plz Help me so that i can complete my work.

My Code is below:

Sub CreateBook()
x = InputBox("Enter WOrkbook Name")
Dim strDir As String
strDir = "E:\Check"
With Application.FileSearch
.LookIn = strDir
.FileName = x & ".xls"
.FileType = msoFileTypeAllFiles

If .Execute() > 0 Then

Workbooks.Open (strDir & "\" & x & ".xls")
Exit Sub
Else

Workbooks.Add.SaveAs (strDir & "\" & x & ".xls")
ActiveWorkbook.Close
End If
End With
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Please stick to the forum rules, you already have a thread on this.

Try adjusting to this

Workbooks.Add
ActiveWorkbook.SaveAs (strDir & "\" & x & ".xls")
 
Upvote 0
I've a problem On This line. & still not removed.

"With Application.FileSearch"


Sub CreateBook()
x = InputBox("Enter WOrkbook Name")
Dim strDir As String
strDir = "E:\CHECK"
With Application.FileSearch
.LookIn = strDir
.FileName = x & ".xls"
.FileType = msoFileTypeAllFiles

If .Execute() > 0 Then

Workbooks.Open (strDir & "\" & x & ".xls")
Exit Sub
Else
Workbooks.Add
ActiveWorkBook.SaveAs (strDir & "\" & x & ".xls")
ActiveWorkBook.Close
End If
End With
End Sub
 
Upvote 0
You don't say which version of Excel you're using but I think Application.FileSearch was removed after 2003.

Try Googling excel application.filesearch to check.
 
Upvote 0
Doesn't the forum rules also request a useful header is used instead of a generic one?

Shariq - have you tried searching for other code that can open a file?
 
Upvote 0
You don't say which version of Excel you're using but I think Application.FileSearch was removed after 2003.

Try Googling excel application.filesearch to check.

In the first thread I asked whcih version and the reply came back with 2003.
 
Upvote 0
I've a problem On This line. & still not removed.

"With Application.FileSearch"


Sub CreateBook()
x = InputBox("Enter WOrkbook Name")
Dim strDir As String
strDir = "E:\CHECK"
With Application.FileSearch
.LookIn = strDir
.FileName = x & ".xls"
.FileType = msoFileTypeAllFiles

If .Execute() > 0 Then

Workbooks.Open (strDir & "\" & x & ".xls")
Exit Sub
Else
Workbooks.Add
ActiveWorkBook.SaveAs (strDir & "\" & x & ".xls")
ActiveWorkBook.Close
End If
End With
End Sub

I have just tested this in version 2002 and it works, I would ask if you have option explicit at the top of the module? Have you checked the references in the VBA screen to make sure that Excel and Office Objects have been selected?

Option Explicit

Sub CreateBook()
Dim x As String
x = InputBox("Enter workbook name")
Dim strDir As String
strDir = "C:\VBA\"
With Application.FileSearch
.LookIn = strDir
.Filename = x & ".xls"
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
Workbooks.Open (strDir & x & ".xls")
Exit Sub
Else
Workbooks.Add
ActiveWorkbook.SaveAs strDir & x & ".xls"
ActiveWorkbook.Close
End If
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,916
Members
452,949
Latest member
beartooth91

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