PDA

View Full Version : Help me Plealse Array of Bookmark, Fields and Autotextentries



carolinagb
11-07-2005, 09:24 AM
Hello please I need that they help me urgent, I am programming directly in the publisher of visual BASIC in Word and I already have my mounted group which has many Bookmark and Autoentries, these are going away to include depending on the values that have the fields of my data base of Access, Exactly my problem is the following one I need to know since I can make an Array of the fields of my data base, Array of bookmark and the AutoTextEntries.

dim BKM_Grp as bookkmark
dim GrpCrt as AutoTextEntries
dim COMP as Fields
redim BKM_Grp(20)
redim GrpCrt(20)
redim COMP(20)
i=0
for i=1 to 20
Selection.GoTo What:=wdGoToBookmark, Name:="BKM_Grp(i)"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
If ActiveDocument.MailMerge.DataSource.DataFields("IMPOR(i)") = (i) Then
Application.DisplayAutoCompleteTips = True
NormalTemplate.AutoTextEntries("GrpCrt(i)").Insert Where:=Selection.Range, _
RichText:=True
End If
If ActiveDocument.MailMerge.DataSource.DataFields("COMP(i)") = i Then
Application.DisplayAutoCompleteTips = True
NormalTemplate.AutoTextEntries("GrpPot(i)").Insert Where:=Selection.Range, _
RichText:=True
End If

thank

Carolina

fumei
11-07-2005, 07:54 PM
I am trying to understand exactly what is the question. Here is your code in the VBA tags - using [ and ].
dim BKM_Grp as bookkmark
dim GrpCrt as AutoTextEntries
dim COMP as Fields
redim BKM_Grp(20)
redim GrpCrt(20)
redim COMP(20)
i=0
for i=1 to 20
Selection.GoTo What:=wdGoToBookmark, Name:="BKM_Grp(i)"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
If ActiveDocument.MailMerge.DataSource _
.DataFields("IMPOR(i)") = (i) Then
Application.DisplayAutoCompleteTips = True
NormalTemplate.AutoTextEntries("GrpCrt(i)").Insert _
Where:=Selection.Range, RichText:=True
End If
If ActiveDocument.MailMerge.DataSource _
.DataFields("COMP(i)") = i Then
Application.DisplayAutoCompleteTips = True
NormalTemplate.AutoTextEntries("GrpPot(i)").Insert _
Where:=Selection.Range, RichText:=True
End If

1. there is no Next to the For...Next loop.

2. you can use, in VBA, .Range.InsertAutoText to place any AutoText where ever you like. You are not limited to the Selection.

Are you trying to insert a lot of AutoText?

3. the following code does not really do much.
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
Could you explain a little more about what you are trying to do? You make an array of bookmarks, then go to each one, and depending on a DataField, insert an AutoText. Is this correct?

What exactly has happened that is not working?

carolinagb
11-08-2005, 07:08 AM
Hello thanks to take care of my question, I have 64 Bookmark, and 41 AutoText in my Template, these must appear depending on the values of fields that I have in my data base the values of my fields go of 1...,5 with decimal, Exactly what I need to know is like making the syntax to make an Array of Bookmark, Autotext and Fields, with the structure of codige I do not have problems is only since I can make those Array. In Theory this is what I must do


For i = 1 To 16 '(This for I use it for the fields of my D.B)
J = 50
K = 1
For J = 50 To 250 '(This For I use for the AutoText)
For K = 1 To 5 '(This for I use to determine it the value that has my field of the D.B)
If com(i) = K Then
Application.DisplayAutoCompleteTips = True
NormalTemplate.AutoTextEntries("GrpCrt(J)").Insert _
Where:=Selection.Range, RichText:=True
Else
J = J + 5
K = K + 0.1
End If
Next J

Next K
Next i

Investigating by all sides I yesterday saw this code that they made an Array of bookmark, but was proving to adapt this code and it does not work to me, I am working with Word 2003 and this code was done in Word97 I was reading and maybe this has something to see, I not that you say your?
WordBasic.EditBookmark Name:="MUNTE" + WordBasic.[Ltrim$](Str(i)), SortBy:=0, GoTo:=1

TonyJollans
11-08-2005, 11:33 AM
Hi Carolina,

I, too, am having difficulty understanding what you are trying to do, but maybe this will help a little

You shouldn't need an array of Bookmarks - Word already has a collection of them. For example, to go to the second bookmarkSelection.GoTo What:=wdGoToBookmark, Name:=ActiveDocument.Bookmarks(2).Name