find if there is a particular folder in a path

  • Thread starter Thread starter nikolaosk
  • Start date Start date
N

nikolaosk

hello there,


i have to check whether a user has saved a particular workbook with the
..htm or .html extension. that is the easy bit.

the user has to save the workbook in a folder on the desktop.

i take the workbook's fullname (see sub below) and check to see if the
last 4 or 5 characters are .htm or .html respectively

please bear in mind that we are not intrested in the name of the
workbook. we just want him to give a name in the workbook and save it
as .htm or .html. see an example below.


C:\Documents and Settings\nkantzelis\Desktop\test\*****.htm

that is the first bit.


now i want to check that if he saved it in the particular folder named
"test".

that is not a problem you might think. just take the 35 or so
characters from the left of the full name and see if test is included.


there is a problem though.



every user is going to log on on a different machine and have a
different user name


so the path will be like this


C:\Documents and Settings\********\Desktop\test\*****.htm


i can take the string using

workbookname= Application.Workbooks(1).fullname


so now workbookname contains something like this


C:\Documents and Settings\********\Desktop\test\*****.htm



is there any way that i can check that in this string there is a "test"
substring?

how can i do it using the Like operator?

that is mi question.





thanks a lot

-----------------------------------------------------------

Sub checkfilenameextension()


'On Error Resume Next

Set app = Application.Workbooks(1)

FullName = app.FullName

MsgBox FullName

MsgBox Right(FullName, 33)


If Right(FullName, 4) <> ".htm" _
And Right(FullName, 5) <> ".html" Then
ECDLANSWER = 2
MsgBox ("error")
Exit Sub
End If


MsgBox ("ok")

End Sub
 
Can you use application.user to define the path fully?

Or use a filescriptingobject - find folder to find the
test folder then the right place
 
this should point you in the right direction:

Dim sP As String,sD as string

sp = Environ("USERPROFILE")
sd = lcase(sp & "\Desktop\")

if lcase(MyBook.fullname) like sd & "*" & ".htm*" then
msgbox "gotcha"
endif


keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 
Back
Top