PDA

View Full Version : Separate into multiple bookmarks



scoobles
05-04-2008, 03:47 AM
Hi, new to this forum...

My userform has some user input data and some auto bought through from ini files. One of these ini files is the address of their office.
The .ini file currently reads for example
MS House | 10 White Street | Wellington | New Zealand (Separator is the vertical bar)
To parse fields to the word doument, I simply use

ActiveDocument.Bookmarks("bkmaddress").Select
Selection.TypeText UserForm1.txtaddress.Text

But, my question is how could I take each section up to the bar and parse them to separate bookmarks in my word document, like address1, address2, address3, address 4.

Any help much appreciated!!

mdmackillop
05-05-2008, 04:30 AM
Sub OpenTextFileTest()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("c:\AAA\MyTest.ini", ForReading, TristateFalse)
'Split text into an array
a = Split(f.readall, "|")
f.Close
'Process the array
For i = 0 To UBound(a)
Selection.TypeText Trim(a(i)) & vbCr
Next
End Sub

fumei
05-05-2008, 05:47 AM
1. is that a real bookmark, or a formfield bookmark?

2. why are you selecting?

3. as Malcolm has shown, you need to read up on string functions (Split, Mid, Replace etc etc etc). As your question has nothing, really, to do with bookmarks. It has to do with manipulating strings.

4. it looks like you are putting the string into the bookmark from a textbox. Are you actually trying to split up the pieces BEFORE putting content into the bookmarks (if they are indeed real bookmarks)? That is, what is going into the textbox? The whole address?

scoobles
05-05-2008, 01:31 PM
Hi Fumei and thanks mdmackillop too.

Fumei I will try to answer your questions as best as I can.
1. Yes - the doc has a bookmarks called bkmaddress, bkmaddress2, bkmaddress3, bkmaddress4.

2. Not sure why I select - its just the way I have always done it! - But I'm no expert...but keen to learn...!

3. You are right - what needs to happen is split...but Im not sure how to do this.

4. You are absolutely right, the text box ("txtaddress") in the user form contains the string, "MS House | 10 White Street | Wellington | New Zealand" and I need to split this essentially into 4 bookmarks in the Word Document. The fact it comes from an.in file is probably irrevelant.

5. The address string in the text box, may sometimes have 3 parts, sometimes 4 - sometimes 5.

Thanks for your questions, I sort of know what I need to do but no idea how to right the code for it.

Any more help is greatly appreciated - thanks for your time to ask the questions.

fumei
05-06-2008, 10:00 AM
1. You may indeed have "bookmarks called bkmaddress, bkmaddress2", but that does not actually answer my question. Which was:

"is that a real bookmark, or a formfield bookmark?"

The answer would be to state if they are formfields, or not. It sounds like they are NOT formfields, i.e. they are "real" bookmarks.

"You are right - what needs to happen is split...but Im not sure how to do this. "

Malcolm has shown you. Use Split.

Why are you using a TextBox to hold:

"MS House | 10 White Street | Wellington | New Zealand"

?????

Textboxes are for user input. Will the user change this? If they are not going to change it, then do not use a textbox.

In the textbox, is:

"MS House | 10 White Street | Wellington | New Zealand"

all one string? So, depending on how you sized the textbox, is it possible the textbox looks like:

MS House | 10 Whit
e Street | Wellingto
n | New Zealand

??

You may also want to change the Split to include the spaces. So instead of something like:

MyStrings = Split(Textbox1.Text, "|")

use:

MyStrings = Split(Textbox1.Text, " | ")