Re: Split Directory\filename into two variables by JBNewsGroup
JBNewsGroup
Mon Dec 06 23:59:04 CST 2004
Hi Bill,
Look at the functions "Instr" (left to right scan) and "InstrRev" (right to
left scan). For Instance:
J = InstrRev (strSourceFile,"\",-1,vbTextCompare)
If (J <= 0) then
-- no backslash, do something --
Else
DirectoryPart = Left$(strSourceFile , J-1)
FileNamePart = Mid$(strSourceFile ,J+1)
End If
In the Lewft$ function change J-1 to J if you want the backslash included.
Instead of Mid$ you could also use Right$.
Jerry Bodoff
<bill_campbell@bcbsmt.com> wrote in message
news:1102395284.439674.312870@z14g2000cwz.googlegroups.com...
> In my macro a user selects a filename using:
>
> With Dialogs(wdDialogFileOpen)
> If .Display Then
> strSourceFile = WordBasic.FilenameInfo$(.Name, 1)
> End If
> End With
>
> I want to split strSourceFile into a directory part, and a filename
> part. I've done this before by starting at the left most point of a
> string, then backing up one character untill a backslash is found, but
> I think there is probably something all ready built into VBA to do this.
>