Word VBA String functions

  • Follow


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
0
Reply Utf 5/17/2010 3:43:01 AM

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@discussions.microsoft.com> wrote in message 
news:05F51783-2625-4ADF-B097-9C0650D6CC36@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 


0
Reply Graham 5/17/2010 4:34:40 AM


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


0
Reply Karl 5/17/2010 10:57:21 PM

2 Replies
864 Views

(page loaded in 2.308 seconds)

10/20/2014 4:37:49 PM


Reply: