Word VBA String functions

J

JillE

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
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Karl E. Peterson

JillE said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top