A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

VB6 to Word Bookmarks nightmare!



 
 
Thread Tools Display Modes
  #1  
Old October 8th, 2007, 04:27 AM posted to microsoft.public.vb.enterprise,microsoft.public.vb.general.discussion,microsoft.public.word.newusers,microsoft.public.word.tables,microsoft.public.word.vba.beginners,microsoft.public.word.vba.general
Blackberry
external usenet poster
 
Posts: 9
Default VB6 to Word Bookmarks nightmare!

Hi All

I could really do with your help as I'm completely stuck.

To explain, I have 1 word doc with 1 table, which consists of about 22 cols
and 10 rows.

Basically I throw pupil names at this table (via VBA) so that the pupils go
into the relevant cells. I had this working perfectly without any form of
formatting, eg I just did a few array loops to check which cell they needed
to go in, concated them up and then 'blobbed' each concated string into the
relevant cell. Perfect, but then I moved onto the task that I really
wanted, which was to format the text colour, text bg colour, bold, italic
and underline styles for each name and this is where I've got major stuck.

Because each name can have diff colours and styles and because I don't know
how many people will go into each cell, I need to do one at a time pass
throughs, so out go my arrays!!

The problem is that I can't get my text to style-ise at all and I think it
is because of the way my bookmarks are setup.

Basically I have an empty bookmark in each cell, got to have this as a lot
of the cells might be empty so text markers would look crap, and when I do
the old:

oNewDoc.Bookmarks(intTableCell).Range.Text = arrPupilData(0, intCurrentRec)
& vbCrLf

I think this text just gets lobbed onto the end of the bookmark so I can't
reference it to format it, because my bookmark doesn't contain any text - is
this right?

Does anybody know how I can get round this bearing in mind that I need to
format each name separately?

Thanks


  #2  
Old October 8th, 2007, 09:45 AM posted to microsoft.public.vb.enterprise,microsoft.public.vb.general.discussion,microsoft.public.word.newusers,microsoft.public.word.tables
Lene Fredborg
external usenet poster
 
Posts: 1,294
Default VB6 to Word Bookmarks nightmare!

I am not sure I understand all details in your description correctly.
However, below you will find a couple of tips that might help you:

When working with bookmark, it is helpful to turn Tools Options View tab
Bookmarks so that you can see the bookmarks (appear as gray square brackets

in the document). This makes it possible for you to see what happens to the
bookmarks if you step through the code (F8).

Then read the article:
http://www.word.mvps.org/FAQs/Macros...AtBookmark.htm

As the article explains, a bookmark is deleted if you use code like yours:
oNewDoc.Bookmarks(intTableCell).Range.Text = arrPupilData(0, intCurrentRec)
& vbCrLf

As also explained in the article, you then need to recreate the bookmark.

In your situation, something like the following should work:

Dim oRange As Range
Set oRange = oNewDoc.Bookmarks(intTableCell).Range
oRange.Text = arrPupilData(0, intCurrentRec) & vbCrLf
ActiveDocument.Bookmarks.Add intTableCell, oRange
Set oRange = Nothing

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"Blackberry" wrote:

Hi All

I could really do with your help as I'm completely stuck.

To explain, I have 1 word doc with 1 table, which consists of about 22 cols
and 10 rows.

Basically I throw pupil names at this table (via VBA) so that the pupils go
into the relevant cells. I had this working perfectly without any form of
formatting, eg I just did a few array loops to check which cell they needed
to go in, concated them up and then 'blobbed' each concated string into the
relevant cell. Perfect, but then I moved onto the task that I really
wanted, which was to format the text colour, text bg colour, bold, italic
and underline styles for each name and this is where I've got major stuck.

Because each name can have diff colours and styles and because I don't know
how many people will go into each cell, I need to do one at a time pass
throughs, so out go my arrays!!

The problem is that I can't get my text to style-ise at all and I think it
is because of the way my bookmarks are setup.

Basically I have an empty bookmark in each cell, got to have this as a lot
of the cells might be empty so text markers would look crap, and when I do
the old:

oNewDoc.Bookmarks(intTableCell).Range.Text = arrPupilData(0, intCurrentRec)
& vbCrLf

I think this text just gets lobbed onto the end of the bookmark so I can't
reference it to format it, because my bookmark doesn't contain any text - is
this right?

Does anybody know how I can get round this bearing in mind that I need to
format each name separately?

Thanks



  #3  
Old October 8th, 2007, 11:21 AM posted to microsoft.public.vb.enterprise,microsoft.public.vb.general.discussion,microsoft.public.word.newusers,microsoft.public.word.tables,microsoft.public.word.vba.beginners,microsoft.public.word.vba.general
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default VB6 to Word Bookmarks nightmare!

See the article "Working with Bookmarks in VBA" at:

http://www.word.mvps.org/FAQs/Macros...hBookmarks.htm

But, if you get the names inside the bookmarks, I am not sure how you think
that will help with applying different formatting to individual names.

To me it seems that the bookmarks are probably not necessary and you could
just as well be using the .Range of the cell instead of the .Range of a
bookmark that is in the cell. I would also think that the formatting would
need to be applied to individual paragraphs within the .Range.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Blackberry" wrote in message
...
Hi All

I could really do with your help as I'm completely stuck.

To explain, I have 1 word doc with 1 table, which consists of about 22
cols
and 10 rows.

Basically I throw pupil names at this table (via VBA) so that the pupils
go
into the relevant cells. I had this working perfectly without any form of
formatting, eg I just did a few array loops to check which cell they
needed
to go in, concated them up and then 'blobbed' each concated string into
the
relevant cell. Perfect, but then I moved onto the task that I really
wanted, which was to format the text colour, text bg colour, bold, italic
and underline styles for each name and this is where I've got major stuck.

Because each name can have diff colours and styles and because I don't
know
how many people will go into each cell, I need to do one at a time pass
throughs, so out go my arrays!!

The problem is that I can't get my text to style-ise at all and I think it
is because of the way my bookmarks are setup.

Basically I have an empty bookmark in each cell, got to have this as a lot
of the cells might be empty so text markers would look crap, and when I do
the old:

oNewDoc.Bookmarks(intTableCell).Range.Text = arrPupilData(0,
intCurrentRec)
& vbCrLf

I think this text just gets lobbed onto the end of the bookmark so I can't
reference it to format it, because my bookmark doesn't contain any text -
is
this right?

Does anybody know how I can get round this bearing in mind that I need to
format each name separately?

Thanks




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:52 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.