From: JillE on
Hi,

I'm looking for a function that can parse a string in Word VBA. Specifically
I want to break a directory path into separate parts so that I can create the
directories/subdirectories. I couldn't find one in Word but I know the Find
function in Excel can do this.

1. Can I use an Excel function in Word VBA? (I believe I may have done this
sometime in the past but can't recall how.)

2. Does anyone know of a better function/method to parse within Word, or can
you suggest a different/better approach?

Thanks,
JillE
From: Graham Mayor on
You can use the Split function - eg

Dim sPath() As String
Dim i As Long
sPath = Split(ActiveDocument.FullName, "\")
For i = 0 To UBound(sPath)
MsgBox sPath(i)
Next i


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


"JillE" <JillE(a)discussions.microsoft.com> wrote in message
news:05F51783-2625-4ADF-B097-9C0650D6CC36(a)microsoft.com...
> Hi,
>
> I'm looking for a function that can parse a string in Word VBA.
> Specifically
> I want to break a directory path into separate parts so that I can create
> the
> directories/subdirectories. I couldn't find one in Word but I know the
> Find
> function in Excel can do this.
>
> 1. Can I use an Excel function in Word VBA? (I believe I may have done
> this
> sometime in the past but can't recall how.)
>
> 2. Does anyone know of a better function/method to parse within Word, or
> can
> you suggest a different/better approach?
>
> Thanks,
> JillE


From: Karl E. Peterson on
JillE wrote:
> I'm looking for a function that can parse a string in Word VBA. Specifically
> I want to break a directory path into separate parts so that I can create the
> directories/subdirectories. I couldn't find one in Word but I know the Find
> function in Excel can do this.

Split ought to do that, as Graham suggests.

> 1. Can I use an Excel function in Word VBA? (I believe I may have done this
> sometime in the past but can't recall how.)

Generally, yes. As long as it doesn't use the (unreferenced) Excel
object model.

> 2. Does anyone know of a better function/method to parse within Word, or can
> you suggest a different/better approach?

Here's the full-meal deal, if you want a cheater...

Classic VB: Create Nested Folders -- Visual Studio Magazine
http://visualstudiomagazine.com/articles/2010/02/04/creating-nested-folders.aspx

--
..NET: It's About Trust!
http://vfred.mvps.org


 | 
Pages: 1
Prev: scroll window to a range
Next: Unprotect Documents