PDA

View Full Version : Solved: create and check bookmarks



white_flag
04-15-2010, 12:49 PM
hello
How can I create 20 bookmarks and wen the code(from userform) is initilized those one (bookmarks) to be checked if there are existing, if not to be created that ones that are mising and to be put in the correct order 1,2,3 ... 20?

thank you

lucas
04-15-2010, 01:04 PM
Are you dealing with a table?

Cause bookmarks are usually used to do what you are trying to do.

white_flag
04-15-2010, 01:08 PM
no ..it is just an template that will create an form via userform. I find that the bookmarks are fitting with my needs.

platform is word 2003

lucas
04-15-2010, 01:11 PM
Why don't you just have all the bookmarks? They are invisible if not used.

white_flag
04-15-2010, 01:24 PM
but if you select an text after the form was created and inside of that text exist an bookmark..run aplication after this will create an error if will not find one bookmark that is necesary for text insertion..or I am wrong?

lucas
04-15-2010, 01:28 PM
it is just an template that will create an form via userform

Why would you do that? Why not just use the userform to ask the questions and fill the bookmarks?

white_flag
04-15-2010, 01:34 PM
yes.like thsi will be, but after that, some extra text was to be inserted (depends on teh context) ..not all the text can be parametrized and if the user will delet the bookmark and will reinitzialized the userform ..will end with an error

lucas
04-15-2010, 01:34 PM
the userform opens when the doc is opened but after you use it once, there is a menu item next to help in the main menu to open the userform again and again.

attached example provided by Gerry(fumie)

lucas
04-15-2010, 01:35 PM
yes.like thsi will be, but after that, some extra text was to be inserted (depends on teh context) ..not all the text can be parametrized and if the user will delet the bookmark and will reinitzialized the userform ..will end with an error

Why? everything can be added from the userform.

lucas
04-15-2010, 01:37 PM
go to tools - options and on the view tab make sure bookmarks is checked.

They don't print but you can see them when working on the doc.

white_flag
04-15-2010, 01:50 PM
thx for the example. in my template some text will take't via comboboxes ..and the comboboxes will insert an standard text from an text file.
text.box for user name data, name of the file ..etc are ok. I had an previous template that do that but I had problems with deleting the bookmarks. that is why I like to know how to create bookmarks and to be put in correct order. also to be check in the begining.

user open the template.. userform do the work (close user form). user add extra text (change his mind and delet some).. save doc. reopen the doc (userform will reinitzialized) ..not bookmark (mising one or two)..error

lucas
04-15-2010, 01:56 PM
in my template some text will take't via comboboxes ..and the comboboxes will insert an standard text from an text file

Two questions. So and why?

combobox selections can go in bookmarks too and why in the heck would you have a text file to populate your combo's.

I'm hoping you have a really good reason because I can't think of one.

white_flag
04-15-2010, 02:12 PM
comboboxes are used to select some standard text. I like to be take it from file to separate the programig(VBA) from standard text. and it is easy to do that from text file (in my point of view). look in attachment

white_flag
04-15-2010, 02:14 PM
I do like this because all the time "standard text" has to be ajusted..and helps after creating the VBA cod. to do not mess with the script

lucas
04-15-2010, 02:25 PM
check this example out. When your done you can save the file. It is created from a template

I had to zip it because the forum doesn't allow .dot file uploads.

just unzip it and double click on it and fill it out.

white_flag
04-15-2010, 02:33 PM
thx for the example. in my case(aslo .dot) I have to make an userform in 4 languages (from there I need to insert optionbuttom)..depends on the option buttom an language will be selected. and will change also the language in userform. so all text will be stored in 4 files texts. sounds resonable?

lucas
04-15-2010, 02:38 PM
Not really. That's why you have code containers(modules)

You will wind up with a file that requires another file.

What does the text file gain for you exactly?

lucas
04-15-2010, 02:48 PM
I hope you don't take my suggestions as overly critical.

They're not meant to be. I just don't understand why you do some of the things you do. There has to be some logic to it or else it's a lack of experience. Not sure at this point.

My intentions are to help if possible.

white_flag
04-15-2010, 02:49 PM
gains all the "standard text" that has to be inserted. all translation for an different language. make it more simple, make apart text from programming.
for example I have to insert one standard text that contains 1000 characters. an in one day I have to change something in text ..so for that I just need to edit the file text. for example I have 10 procedures of instaling insulation (diffrent materials) 12 types of cladings. procedurs an security on site (are diffrent from site to site - but are standard) I do not need all of then just to point out whitch one to be insertedd (comboboxes will do that) ..etc. I am close?

white_flag
04-15-2010, 02:55 PM
I know ..I aprecieted that an VBA guru talk to me. I do not take this like critic . Just the filosofy here is a bit diffrent (involve an extra file)

lucas
04-15-2010, 03:03 PM
gains all the "standard text" that has to be inserted. all translation for an different language. make it more simple, make apart text from programming.
for example I have to insert one standard text that contains 1000 characters. an in one day I have to change something in text ..so for that I just need to edit the file text. for example I have 10 procedures of instaling insulation (diffrent materials) 12 types of cladings. procedurs an security on site (are diffrent from site to site - but are standard) I do not need all of then just to point out whitch one to be insertedd (comboboxes will do that) ..etc. I am close?

Well, I can begin to understand that. You know you can add that text to a textbox as in the examples above and then insert it directly into a bookmark. Or even go around the textbox and just insert the textfile contents into the bookmark.

white_flag
04-15-2010, 03:03 PM
ok ..I do not know how to put translation an the rest of the standard text in modules (containers)..can you give me in this case an example?

white_flag
04-15-2010, 03:15 PM
this is another example why I use the file text (it is excel but maybe it make clear my point of view). please look in attachment

lucas
04-15-2010, 03:24 PM
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "Test1"
.AddItem "Test2"
End With
Call a
End Sub

The Call a part in the initialize calls sub a in module 2

I used two different methods to break the lines:

& Chr(10) &

& vbCrLf &

white_flag
04-15-2010, 03:36 PM
thx for example. this part I allready know how to do it. but back on bookmarks.. how can be created 20 bookmarks like this:

bmk1
bmk2
bmk3
..
bmk20

or bmk1, bmk2 ...bmk20 from VBA

lucas
04-15-2010, 03:37 PM
I looked at your excel file and text files. I wouldn't do it that way personally.

I would put them on a sheet that can be hidden later and put each combo box rowsource in a named range on the hidden sheet.

the rowsource property is found by making sure the properties window is showing. In the VBE view-properties if not showing.

select the combo you wish to put the named range into as rowsource and then in the properties window look for rowsource and put the named range in there and hit enter.

see attached example

lucas
04-15-2010, 03:47 PM
thx for example. this part I allready know how to do it. but back on bookmarks.. how can be created 20 bookmarks like this:

bmk1
bmk2
bmk3
..
bmk20

or bmk1, bmk2 ...bmk20 from VBA

Another Gerry Knight example. It requires a table. I don't know how you would put them in without some kind of reference. That's usually what bookmarks are good for. Placing text exactly where you want it.

I still don't know why you would want to do that but here's the example.

white_flag
04-15-2010, 04:00 PM
thx for the example .. I have an template that is acting like this. Thake date from excel sheet. but I want in this case something difrent (excel) .. this is for excel (diffrent story). Back to bookmarks..can you light me in creation of bookmarks?

white_flag
04-15-2010, 04:06 PM
hmm ..good point (without some kind of reference)..but still those bookmarks can be created in the exact order 1,2,3 etc 20

white_flag
04-15-2010, 04:26 PM
and how those bookmark can be check if are existing in document and if not to be created?

white_flag
04-16-2010, 12:04 AM
Sub makeBK()
For i = 1 To 10
ActiveDocument.Bookmarks.Add Name:="temp" & i
If ActiveDocument.Bookmarks.Exists("temp" & i) = False Then
ActiveDocument.Bookmarks.Add Name:="temp" & i
End If
Next

End Sub


now the reference

macropod
04-16-2010, 12:37 AM
Hi white flag,

Creating bookmarks is easy. The real problem is knowing where to create them. For what you're trying to do, if you know where the bookmarks have to go, you really don't need them - you can simply insert the data there more easily than you can insert and populate a bookmark.

white_flag
04-16-2010, 01:48 AM
I saw that, searching on internet.
but I would like to be created an number of bookmarks(i) in the end of the document like this [bkm1] [bkm2] [bkm3] ..[bkm(i)] or like this
[bkm1]
[bkm2]
[bkm3]
.
.
[bkm(i)]

white_flag
04-16-2010, 03:22 AM
Sub makeBK()
For i = 1 To 4
If ActiveDocument.Bookmarks.Exists("Name" & i) = False Then

Selection.EndKey Unit:=wdStory
With ActiveDocument
.Bookmarks.Add Name:="Name" & i
.Bookmarks.DefaultSorting = wdSortByName
.Bookmarks.ShowHidden = False
.Bookmarks("Name" & i).Range = " "
End With
End If
Next
End Sub


[bk1] [bk2] ...[bk(i)]


Sub makeBK()
For i = 1 To 4
If ActiveDocument.Bookmarks.Exists("Name" & i) = False Then

Selection.EndKey Unit:=wdStory
With ActiveDocument
.Bookmarks.Add Name:="Name" & i
.Bookmarks.DefaultSorting = wdSortByName
.Bookmarks.ShowHidden = False
.Bookmarks("Name" & i).Range = chr(10)
End With
End If
Next
End Sub


[bk1]
[bk2]
...
[bk(i)]

now if one is deleted for example [bk2] to be inserted were belongs between [bk1] and [bk3]

white_flag
04-16-2010, 06:01 AM
Sub makeBK()
For i = 1 To 4
If ActiveDocument.Bookmarks.Exists("bkm" & i) = False Then
With ActiveDocument
.Bookmarks.Add Name:="bkm" & i
.Bookmarks.DefaultSorting = wdSortByName
.Bookmarks.ShowHidden = False
End With
End If
Selection.EndKey Unit:=wdStory, Extend:=wdMove
With ActiveDocument
.Bookmarks.Add Name:="bkm" & i
.Bookmarks.DefaultSorting = wdSortByName
.Bookmarks.ShowHidden = False
.Bookmarks("bkm" & i).Range = Chr(10)
End With
Next
End Sub

fumei
04-16-2010, 09:30 AM
I am trying to follow what the heck you are trying to do here. Are you trying to create four sequential bookmarks at the end of the document.

That is, a bookmark followed by a paragraph mark, another bookmark followed by a paragraph mark, another bookmark followed by a paragraph mark...

BM
BM
BM
BM

????????????????

Strange. I fail to see the purpose for this, as macropod points out, if you want to put text sequentially at the end of a document, you certainly do not need bookmarks to do this. Bookmarks are useful to put text at a specific location within a document.

Still

Dim var
' go to the end of the doc
Selection.EndKey Unit:=wdStory
' put four bookmarks
For var = 1 To 4
ActiveDocument.Bookmarks.Add Name:="Name" & var, _
Range:=Selection.Range
With Selection
.Collapse 0
.TypeParagraph
End With
Next

white_flag
04-16-2010, 09:39 AM
fumei, thx for the solution.
if the bookmarks are not a good solution ..tell me a better one

fumei
04-16-2010, 09:40 AM
Tell me EXACTLY what you are doing first.

white_flag
04-16-2010, 09:54 AM
ok ..I have an userform multipage:
pag1
name
adress
location
telefon etc (text.boxes)
etc
pag2
who make the document
email
telefon
scope (text.boxes)
etc
page3
security
security working on site type one
security working on site type two
...
etc.
pag4
technical aspects - pipes
technical data from materials 1 (comboboxes)
technical data from materials 2 (comboboxes)
technical data from materials 3 (comboboxes)
pag 5
technical aspects II - tanks
technical data from materials 1 (comboboxes)
technical data from materials 2 (comboboxes)
technical data from materials 3 (comboboxes)
.. here are more

between those fields (I call then standard text) some time a text has to be
inserted like if tracing for pipes are involve ..or if it is an special conditzion that has to be point out. ok from this will be create an template (.dot) thsi one will be save on server. Open and will create an normal doc file. Some time you need to make an revision to text (that was save in taht document) ..because are extra stuff that wil be add later (in the project) ..wen you start the doc ..the user form will start again ..and will take the data and put it in textboxes (just in text boxes, in comboboxes I find it to difficult ..index.list) .then will create an document with revision one.. for that one I was consider that bookmarks will be helpful.

white_flag
04-16-2010, 10:17 AM
to make document just for one time (without any revision) is not an problem ..what I find difficult is ..wenn some one open the saved .doc and delete some bookmarks ..save't and open it again ..will be an error

lucas
04-16-2010, 10:25 AM
They can't delete bookmarks if you don't let them have access to the document.

That's the point of the userform which can still be re-called if it is available to the document. You said the template would be on the server.

I explained this to you and gave you examples.

white_flag
04-16-2010, 10:52 AM
ok ..like this will be more easy ..no more messing around with bookmarks

macropod
04-16-2010, 11:29 PM
and how those bookmark can be check if are existing in document and if not to be created?

Sub Demo()
Dim i As Integer
With ActiveDocument
For i = 1 To 12
If Not .Bookmarks.Exists("My_Bookmark" & i) Then
.Range.InsertAfter vbCr
.Bookmarks.Add "My_Bookmark" & i, .Characters.Last
End If
Next
End With
End Sub