Word VBA String functions

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
Utf
5/17/2010 3:43:01 AM
word.vba.general 1023 articles. 0 followers. Follow

2 Replies
1365 Views

Similar Articles

[PageSpeed] 55

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
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
Karl
5/17/2010 10:57:21 PM
Reply:

Similar Artilces:

problem with BOLD. ITALIC...using Word as editor
I compose a msg using Outlook. Word is the editor. I set a word in bold ot italic. I send msg to myselg, reading in Outlook. The bold or italic is gone. What to do? Thanks, Leo Are you sending the message as text only? If so all formatting will disappear. If you want to retain your formatting you'll need to send your messages as HTML. You can check this in your Outlook options. -- Martin Sketchley | www.msketchley.pwp.blueyonder.co.uk (remove EGGBEANSANDSPAM to reply by e-mail) ...

Printing WORD docs from a form
I have a button on a form and I want it to print a Word mail merge document that contains data from the database that is linked to my application. I'm using the following code but always get a 5922 error - Word can't open the source... All variable names contain valid data, so that's NOT the problem. With appWord .Visible = True .Documents.Open pathdocname With .ActiveDocument.MailMerge .MainDocumentType = wdFormLetters strConnection = "DSN=MS Access Databases;" _ & "DB...

Windows XP: Open file in read-only: Word, Excel, Visio
I'm often sharing files on a network drive with someone. Often, one of us knows that we don't need to open a file for modification, and we only need read-access. Is there a way to open a file in read-only mode so that when someone does need to open it for modification, the read-only user is not blocking that? If there is not a way to do this native to Windows XP, is there a way to do it from the three applications that we use most, namely Word, Excel, Visio? All are 2003 versions. Thx. I used to save files like this in "read only recommended" mode. File|SaveAs|Tools|Ge...

Not enough memory error trying to open a Word X file
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Error message: &quot;There is not enough memory or disk space available to complete the operation&quot; when trying to open a Word X file in Office 2008 in Leopard or Snow Leopard on iMac that works fine in Word X despite resaving a new version. Any tips? Not enough information to answer. Check that OS X and Office 2008 have the latest updates applied. Use Disk Utility to Repair Permissions. Check the access your user ID has to the system Temporary folder (don't worry about this if you ar...

Cannot upgrade to Word 2007 from Word 2002 as word crashes when tr
We have a word add in that programatically inserts an auto text table then adds rows to it. This works ok in Word 2002 but occasionally crashes in Word 2007 - this is not a consistent crash when we carry out the same operation it happens in no specific sequence. The only place we are able to track it down to is the auto text table inserting rows. Word itself is crashing. We are using COM AddIn written in VB6. Does anyone know of any key differences/issues between Word 2002 and Word 2007 that could cause such an error. Or is there a better way to attach a debugger/word debugg...

The mode function
I looked up the capability of the mode function and it said that the only time it should return an #N/A value is when there are not two names, or numbers in a range. I am not sure why but for the given stock market sectors, the function below always returns a #N/A when it should return in this case the name finance. Any suggestions? ComputerandTechnology BasicMaterials Retail-Wholesale Medical Finance Finance IndustrialProducts Utilities Medical Finance =MODE(S832:S841) -- Thank you! Can't be used on text. -- Gary''s Student - gsnu200908 "Do...

Word 2007 TOC Not saving settings...
Hi there, When I use Word 2007 TOC, and I want to edit an existing TOC layout, etc. It wont remember my settings. I go to References Table of Contents Insert Table of Contents Then I make my chnages here, such as changing the levels of the various styles and how they show up Then I select OK, the TOC is created.. I then decide I don't like the changes I made, or I need to include another style So I go to References Table of Contents Insert Table of Contents The changes I made are no where to be seen. I have to start over from scratch. What am I doing wrong,...

Match function with time
I am trying to use the MATCH function to find last train that I can catch to reach my destination before, on time or just after a given time. The arrival times are E1:E10 and also named as ArriveTime and is formatted HH:MM AM/PM The target time in H1 and is also formatted as HH:MM AM/PM. For test purposes I am using 10:00AM and ArriveTime contains 09:59,10:00 and 10:01AM Using =MATCH($H$1,ArriveTime,0) or =MATCH($H$1,ArriveTime,1) work fine and both return the row (5), but =MATCH($H$1,ArriveTime,-1) returns #N/ A instead of the row of the earliest train after the target. I am using Excel 2007 ...

Encoded Word Documents
We have recently purchased a new pc with windows 7 and have installed the Microsoft Office software however when I got to open a PDF or word document from a webpage a file conversion pop up box comes up and asks for me to select the encoding that makes the document readable but none of them do. even the windows default doesn't work...... You cannot open a pdf in Word. You need Adobe Reader. What you're downloading from a web page probably isn't a Word document, either. On May 27, 4:25=A0pm, Newuser <Newu...@discussions.microsoft.com> wrote: > We have rece...

Quartile Function
I would like to use a formula to return which quartile the given data array falls into- that is I would like to return 0,1,2,3,4. 0= min, 1=25%, 2=50%, etc. The quartile function only returns the value of the various quartiles, while I need to know within which quartile the value falls. Any help is appreciated. On Tue, 15 Mar 2005 01:01:02 -0800, "tika528" <tika528@discussions.microsoft.com> wrote: >I would like to use a formula to return which quartile the given data array >falls into- that is I would like to return 0,1,2,3,4. 0= min, 1=25%, 2=50%, >etc. &g...

Where are my saved word?
I open the attachment directly, it is .doc and edit it in a loong time, what I ask is when I press save button and it show nothing so I think it succes. And I close it!! I can't find it now, could you help me ????? Thanks! It is gone. When editing an attachment, you /must/ save it to your HDD first, edit it and then reattach it. -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA "smezsc" <smezsc@discussions.microsoft.com> wrote in message news:3AF0D07A-D490-4819-A649-1C5FC079027F@microsoft.com... >I open the attachment dire...

VBA Macro Error
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC Hello, I�m running in a pretty bad problem: If I write in MSOffice 2008 a number followed by a letter like "5a" on a new line I get an error "This command is not available in this Version of Microsoft Word" It seems that word want�s to make a lookup for a VBA script - which is not supported anymore, so in panic they write the message on the screen. But instead I really want to write only 5a. Is there a button to switch of those interpretations? It was not an issue with 2004 and not on windows. Any...

(User Defined) Function for Copy&Paste?
Dear Excel Power Users, I have a problem with copy of formated text to another sheet. Cell contains multiple fonts and sizes but copies only the first font and size as format for the whole contents example: Sheet1!A1 : mahIgGABEI (a=alpha) (ABEI=superscript) using the " =A1 " function in for example Sheet2: Sheet2!A1=Sheet1!A1 becomes mahIgGABEI (all normal Arial) using Copy&Paste works fine ! Can this be solved using a function instead of Copy&Paste specific cells to other sheets by hand, I cannot vindt the function doing what Copy&Paste does. I've found th...

Bulk E-mail with Non-Word Attachment
I need to be able to send a bulk e-mail (not from a template) with attachments of a number of different document types to a group of contacts (could be from a Saved View or Marketing List). Direct E-mail, Quick Campaigns and Mail Merge do not seem to be able to do this. Is there another way? Thanks. Nope. Take a look at this blog http://groups.google.com/group/microsoft.public.crm/msg/0a84808e99645006?dmode=source&hl=en Cheers, Venkatesh ---- On May 16, 11:57 pm, DStella <DSte...@discussions.microsoft.com> wrote: > I need to be able to send a bulk e-mail (not from a tem...

Word Wrap: Where is it in Word 2007?
I have Googled and Googled and cannot find any page that tells me where Word Wrap is. For such a basic feature you'd think it would be under View. Suggestions? On Mon, 18 Jan 2010 18:55:28 -0600, "Gary Gary" <blah@blah.blah> wrote: >I have Googled and Googled and cannot find any page that tells me where >Word Wrap is. For such a basic feature you'd think it would be under >View. Suggestions? The reason you aren't finding anything is that word wrap is automatic in Word unless you turn it off, or possibly if something is broken. Wha...

Referencing other Office programs in a Excel VBA App
I din't like the way my previous post sounded, so i'm reposting... All, My Excel VBA programming is decent enough when I'm only working with Excel. However, I'm trying to expand my knowledge base and frequently I wish I could better interact with other Office programs, such as Outlook, in my Excel VBA apps. To better illustrate my question, here's a piece of code that works great (it populates a user form list with Outlook addresses) but I don't fully understand. Private Sub UserForm_Activate() Dim x As Integer Set objOL = CreateObject("...

Getting Excel to return Hiragana using code/char functions
I have a Japanese computer which does this perfectly, but when I tried to use the worksheet on an English computer with Japanese language enabled, it only came up with errors. The code it was returning for the Japanese characters was much to low & putting in higher codes meant it didn`t recognise it. What can I do to make it work? ...

word 2002 compatibility with Windows 7
My niece is handicapped and her new computer has Office 2007 on it. She would like me to install word 2002 on her Inspiron 546. Is this possible? Yes, if it is licensed for another computer. If it is an OEM version, it cannot be installed on any but the system with which it was sold. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org "Sharon F" <SharonF@discussions.microsoft.com> wrote in message news:216DC8A6-4282-46A1-876D-B4D76E793F33@microsoft.com... > My niece is handicapped and her new computer ...

Word 2007--pesky black dotted line
Hello: I have this moderately thick, black, dotted line running between paragraphs on my page. I have no idea how to get this thing to go away. Please, could you tell me what to do to get rid of it? Thanks, John Saxon See here http://word.mvps.org/faqs/formatting/CantGetRidOfLine.htm -- Mary Sauer MVP http://msauer.mvps.org/ "John" <someone@someplace.invalid> wrote in message news:2B22C75C-4BBB-43E0-8C67-BE19C55B818C@microsoft.com... > Hello: > > I have this moderately thick, black, dotted line running between paragraphs on > my p...

Paste function is greyed out in the toolbar and I can't use ctl V
Hello, I have a problem the my paste function. Whenever I copy (copy seems to work ok with the marquee and selection process) and then try to paste the data into another cell, it won't let me. the Paste function is greyed out. The worksheet is unprotected and I'm in Excel 2003. Any ideas. Bob Reynolds ...

Formula to extract the last word from a cell
Anyone know of a formula that will extract the last word from a cell. For example if cell contains the text: Best available title How could I produce the result: "title" (And preferably be able to fill the formula down the column to get the last word from other cells in the column as well.) Thanks for any suggestions. =MID(A10,FIND(CHAR(1),SUBSTITUTE(A10," ",CHAR(1),B10))+1,99) -- __________________________________ HTH Bob "Dave K" <fred.sheriff@gmail.com> wrote in message news:c4347e85-a3e2-4abe-b632-88643d4d244c@w7g2000hsa.googlegroups.com... &...

Default DOCX file to open w/ Word 2007 and DOC to open with Word 2
Hi, I am trying to convert several hundred mail merge documents from Word 2003 to Word 2007. Currently, if I double click a document to open it, it opens in whichever version of Word was run last. What I would like, is for ..DOC files to open in 2003 and .DOCX files to open with 2007. I've tried to change the file types to do this, but can't make it 'stick'. Any suggestions? To prevent the two Word versions from "competing" over the file associations, see the "Hacking the Registry" section of the article at http://www.gmayor.com/Toolbars_in_wor...

copying Arabic into Word document on Mac
I am trying to copy and paste an Arabic word from the web into a multi-lingual Word document on my Mac but am having terrible trouble. It always comes out either backwards (left-right) or with the letters not correctly joined up (an Algerian colleague tells me). I have tried making the web page I am copying from into a PDF first, but doesn't help. Any advice greatly appreciated. Michael <huanzuiju@googlemail.com> wrote: > I am trying to copy and paste an Arabic word from the web into a > multi-lingual Word document on my Mac but am having terrible trouble. > It always co...

limiting number of words in textbox in Word 2007
I created a Textbox in MS-Word 2007 by going to the Developer option->then chose Design Mode, then Legacy Tools->Text box Field. The MultiLine and Enterkey properties are True and the rest are default values. Is there a way I can limit the number of words to a certain number? I realize there is a way to limit the number of characters in the Textbox by the Maxlength value. Also, is it possible that a message appears when the user exceeds the maximum length informing him about that. Do I need to use VBA code or do the inbuilt features of word allow me to do that? The short ...

microsoft word
is it possible to create a macro to open up word and copy and paste some data from excel into it. Thanks Debra Dalgleish has an example at: http://www.contextures.com/xlcomments03.html#CopyToWord It's a way of copying comments in a worksheet to a word document. But you can see the structure nicely. head wrote: > > is it possible to create a macro to open up word and copy and paste some data from excel into it. Thanks -- Dave Peterson ec35720@msn.com ...