?
Solved

Word Automation - paragraphs and bullets

Posted on 2001-08-13
15
Medium Priority
?
1,027 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

801 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