Ask Question Forum:
C
O
M
P
U
T
E
R
2
8
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Y-position of the mouse cursor
Attachment:===
one new other file called "data2010" without the word of "advanced". The code is as
follows. But it won't create file of data2010 , and then I solved the problem
by rename the similar name file of "advanceddata2010" to "advacnedata", re-run
the program, and then the file of "data2010" is shown up and created
So my question is how to filesearch the eaxct name of file in VBA ?
Please advise
Duncan
Sub main()
Dim wkdir As String
Dim datafilename As String
wkdir = "d:excel"
datafilename = "data2010"
Call DoesWorkBookExist(wkdir, datafilename)
Sub DoesWorkBookExist(wkdir As String, datafilename As String)
'Test to see if a Workbook exists
Dim i As Integer
With Application.FileSearch
.LookIn = wkdir
'* represents wildcard characters
.Filename = datafilename
If .Execute > 0 Then 'Workbook exists
' Debug.Print "There is a Workbook."
Else 'There is NOt a Workbook
' Debug.Print "The Workbook does not exist"
'Workbooks.Add
Workbooks.Add.SaveAs wkdir & datafilename
ActiveWorkbook.Close False
End If
End With
End Sub
It's a placeholder.
Trying again...
exact match:
If Dir("d:excelsomefile.xls") <> "" Then
'code for file exists
Else
'code for file does not exist
End If
partial match:
If Dir("d:excel*somefile*.xls*") <> "" Then
'code for at least 1 match
Else
'code for no matches
End If
It's a placeholder.
Trying again...
exact match:
If Dir("d:excelsomefile.xls") <> "" Then
'code for file exists
Else
'code for file does not exist
End If
partial match:
If Dir("d:excel*somefile*.xls*") <> "" Then
'code for at least 1 match
Else
'code for no matches
End If
It's a placeholder.
Trying again...
exact match:
If Dir("d:excelsomefile.xls") <> "" Then
'code for file exists
Else
'code for file does not exist
End If
partial match:
If Dir("d:excel*somefile*.xls*") <> "" Then
'code for at least 1 match
Else
'code for no matches
End If
It's a placeholder.
Trying again...
exact match:
If Dir("d:excelsomefile.xls") <> "" Then
'code for file exists
Else
'code for file does not exist
End If
partial match:
If Dir("d:excel*somefile*.xls*") <> "" Then
'code for at least 1 match
Else
'code for no matches
End If
It's a placeholder.
Trying again...
exact match:
If Dir("d:excelsomefile.xls") <> "" Then
'code for file exists
Else
'code for file does not exist
End If
partial match:
If Dir("d:excel*somefile*.xls*") <> "" Then
'code for at least 1 match
Else
'code for no matches
End If
It's a placeholder.
Trying again...
exact match:
If Dir("d:excelsomefile.xls") <> "" Then
'code for file exists
Else
'code for file does not exist
End If
partial match:
If Dir("d:excel*somefile*.xls*") <> "" Then
'code for at least 1 match
Else
'code for no matches
End If
It's a placeholder.
Trying again...
exact match:
If Dir("d:excelsomefile.xls") <> "" Then
'code for file exists
Else
'code for file does not exist
End If
partial match:
If Dir("d:excel*somefile*.xls*") <> "" Then
'code for at least 1 match
Else
'code for no matches
End If
It's a placeholder.
Trying again...
exact match:
If Dir("d:excelsomefile.xls") <> "" Then
'code for file exists
Else
'code for file does not exist
End If
partial match:
If Dir("d:excel*somefile*.xls*") <> "" Then
'code for at least 1 match
Else
'code for no matches
End If