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.

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.
>



Re: Split Directory\filename into two variables by bill_campbell

bill_campbell
Tue Dec 07 01:15:20 CST 2004

I found (mostly by luck) that by switching the number following .Name
to 5 and 3, I could pull the information I needed.
> > strSourceFile = WordBasic.FilenameInfo$(.Name, 1)


Re: Split Directory\filename into two variables by bill_campbell

bill_campbell
Tue Dec 07 01:15:48 CST 2004

I found (mostly by luck) that by switching the number following .Name
to 5 and 3, I could pull the information I needed.
> > strSourceFile = WordBasic.FilenameInfo$(.Name, 1)


RE: Split Directory\filename into two variables by PeteBennett

PeteBennett
Tue Dec 07 07:25:03 CST 2004

It's even easier to use FileSystemObject (you'll need to add in a reference
to Microsoft Scripting Runtime to get it to work)

Dim fso as FileSystemObject

Debug.Print fso.GetParentFolderName("c:\temp\harry.xml")
Debug.Print fso.GetFileName("c:\temp\harry.xml")

Will give you the information you need. Play with it and you'll see it's a
pretty good little file handler. It even supplies read and write functions
as well.



"bill_campbell@bcbsmt.com" wrote:

> 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.
>
>

Re: Split Directory\filename into two variables by JBNewsGroup

JBNewsGroup
Tue Dec 07 08:18:48 CST 2004

Hi Pete,

I have been using the FileSystemObject for a while and I did not realize
that I could do I/O with it. I am going to check it out. It is like a
friend says, "read the book when you need it".

Thanks for the tip.

Jerry Bodoff

"Pete Bennett" <PeteBennett@discussions.microsoft.com> wrote in message
news:2C8030D8-6CA5-4D20-9411-11C0D7D1373B@microsoft.com...
> It's even easier to use FileSystemObject (you'll need to add in a
reference
> to Microsoft Scripting Runtime to get it to work)
>
> Dim fso as FileSystemObject
>
> Debug.Print fso.GetParentFolderName("c:\temp\harry.xml")
> Debug.Print fso.GetFileName("c:\temp\harry.xml")
>
> Will give you the information you need. Play with it and you'll see it's
a
> pretty good little file handler. It even supplies read and write
functions
> as well.
>
>
>
> "bill_campbell@bcbsmt.com" wrote:
>
> > 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.
> >
> >