?
Solved

Word Automation - paragraphs and bullets

Posted on 2001-08-13
15
Medium Priority
?
1,039 Views
Last Modified: 2010-05-18
As a follow-on to this question:

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=msaccess&qid=20164520 

I now want to produce a report in Word 97 based on an Excel 97 spreadsheet. I want some addition to this code which will mean that we loop through the code transferring row by row the text from columns A->D but putting a bullet point at the start of the text from column A. I would also like to have a vbcrlf seperating every row of the spreadsheet when shown on the Word document - any ideas?


Private Sub cmdTest_Click()
Dim wordapp As Word.Application
Dim worddoc As Word.Document
Set wordapp = CreateObject("Word.Application")
wordapp.Documents.Add
wordapp.Visible = True
Set worddoc = wordapp.ActiveDocument
introw = 1
Do While Trim(Worksheets("Highlights").Range("A" & introw).Value) <> ""
wordapp.Selection.EndKey wdStory
wordapp.Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
       wdBulletGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _
       wdListApplyToWholeList
wordapp.Selection.TypeText Worksheets("Highlights").Range("A" & introw).Value 'Type text from Excel in selection (cursor)
wordapp.Selection.TypeParagraph
wordapp.Selection.EndKey wdStory
wordapp.Selection.TypeText Worksheets("Highlights").Range("B" & introw).Value 'Type text from Excel in selection (cursor)
wordapp.Selection.TypeParagraph
wordapp.Selection.EndKey wdStory
wordapp.Selection.TypeText Worksheets("Highlights").Range("C" & introw).Value 'Type text from Excel in selection (cursor)
wordapp.Selection.TypeParagraph
wordapp.Selection.EndKey wdStory
wordapp.Selection.TypeText Worksheets("Highlights").Range("D" & introw).Value 'Type text from Excel in selection (cursor)
wordapp.Selection.TypeParagraph
introw = introw + 1
Loop
End Sub
0
Comment
Question by:robertsmith28
  • 10
  • 4
15 Comments
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6380596
VBcrlf equals to:
Selection.TypeParagraph

WoK ;O)
0
 

Author Comment

by:robertsmith28
ID: 6381367
Thanks - any ideas how I prevent the bullets at the start of line?
0
 
LVL 1

Expert Comment

by:eeevans
ID: 6382254
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:eeevans
ID: 6382259
0
 
LVL 1

Expert Comment

by:eeevans
ID: 6382275
0
 
LVL 1

Expert Comment

by:eeevans
ID: 6382282
0
 
LVL 1

Expert Comment

by:eeevans
ID: 6382284
0
 
LVL 1

Expert Comment

by:eeevans
ID: 6382286
0
 
LVL 1

Expert Comment

by:eeevans
ID: 6382290
0
 
LVL 1

Expert Comment

by:eeevans
ID: 6382434
You might want to put it in Word as a table instead.
To do that, I would have 4 strings that you concatonate
the row value to the end of it separating it by vbTab and
then get the current position.
Then do a
  Selection.typetext sRowA & vbCR & vbCR & sRowB & vbCR & vbCR & sRowC & vbCR & vbCR & sRowD
Then get the current position again and do a
  Range(initPosition, finalPosition).Select
  Selection.ConvertToTable(wdSeparateByTabs,introw)

At this point you could format it to highlight the
background of every other line to maybe give the same
effect as the bullets.

Would this work for you?

BTW, the ConvertToTable is much faster than stuffing into
table cells.

Regards,

eeevans
0
 

Author Comment

by:robertsmith28
ID: 6384008
Thanks eeevans,
The I'm producing needs to be in an exact format - so it's got to be the bullet-points, unfortunately. Thanks for the tips though.
0
 
LVL 1

Expert Comment

by:eeevans
ID: 6385742
No problem Robert.  To try and understand your format an example of what you are trying to produce would help but, I assume you need it to look like

. A1_text  

. B1_text

. C1_text    

. D1_text

. A2_text  

. B2_text    

. C2_text    

. D2_text


etc. where the periods in front are to be bullets and blank lines are in between.  Is this correct?

To do this you would just add the code to turn on the bullets before each wordapp.Selection.TypeText and add & vbCR & vbCR & vbCR at the end of that line.  The second vbCR will give you the blank line and the third vbCR will drop to the next line and turn off the bullets for the blank line and the current line.  Then you just repeat the code to turn on bullets etc.

Hope that helps,

eeevans
0
 

Author Comment

by:robertsmith28
ID: 6387270
Thanks for sticking with me eeevans, I'm new to working with Word so it may well be that the answer is simple but I can't see why my code does n't do what I think it should! What I would like it to do (using your format) is:

<bullet> A1_text
B1_text
C1_text
D1_text

<bullet> A2_text
B2_text
C2_text
D2_text

<bullet> A3_text
etc..

What I get is quite different. Any ideas?
0
 
LVL 1

Accepted Solution

by:
eeevans earned 800 total points
ID: 6388182
Okay, after your A#_text put this line

wordapp.Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph

that should turn off the bullets for the last 3 items.  Also it looks like you need to add another

wordapp.Selection.TypeParagraph

after the last one in your code above to give the blank line between sets.

Let me know if that gets you closer.

eeevans
0
 

Author Comment

by:robertsmith28
ID: 6388918
That's grrreat! Job done. Thank you for all your help!

Rob :->
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question