View Single Post
  #16   Report Post  
Posted to microsoft.public.excel.programming
Grace[_4_] Grace[_4_] is offline
external usenet poster
 
Posts: 106
Default Filename problem

Thanks!

"Dave Peterson" wrote in message
...
One mo

Option Explicit
Sub testme01()

Dim myFilename As String
Dim MGR_SHORT_NAME As String
Dim testStr As String

MGR_SHORT_NAME = "something that you set???"

myFilename = MGR_SHORT_NAME & Sheets("Inputs").Range("E11").Value & _
"SUMPRF" & ".L00"

MsgBox "|" & myFilename & "|"
'| may help see extra spaces in the filename

testStr = ""
On Error Resume Next
testStr = Dir(myFilename)
On Error GoTo 0

If testStr = "" Then
MsgBox "Filename: " & myFilename & " doesn't exist"
End If

End Sub

This assumes that sheets("Inputs") exists in the activeworkbook. (If you

have
doubts, you may want to include a check for that, too.)

Option Explicit

Sub a()

Dim myFilename As String
Dim MGR_SHORT_NAME As String
Dim testStr As String
Dim testWks As Worksheet

MGR_SHORT_NAME = "something that you set???"

Set testWks = Nothing
On Error Resume Next
Set testWks = ActiveWorkbook.Worksheets("inputs")
On Error GoTo 0
If testWks Is Nothing Then
MsgBox "It doesn't exist!"
Exit Sub '?
End If

myFilename = MGR_SHORT_NAME & testWks.Range("E11").Value & _
"SUMPRF" & ".L00"

MsgBox "|" & myFilename & "|"
'| may help see extra spaces in the filename

testStr = ""
On Error Resume Next
testStr = Dir(myFilename)
On Error GoTo 0

If testStr = "" Then
MsgBox "Filename: " & myFilename & " doesn't exist"
End If

End Sub



Grace wrote:

Is there something wrong with the following code?

myFilename = MGR_SHORT_NAME + Sheets("Inputs").Range("E11").Value +

"SUMPRF"
+ ".L00"

It keeps bombing out when it goes to find this file, because the actual
file, of course, was named so that it has the MGR_short_name in the

front
part of its name, but the macro doesn't seem to recognize it, i.e., when

it
responds that it cannot find the file, the name it says it is looking

for,
does not have this first part.

Thanks,
Grace


--

Dave Peterson