Solved

Word Automation - paragraphs and bullets

Posted on 2001-08-13
15
995 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 200 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever had the experience that you had to follow 10 steps over and over again every time when you need to nicely forward an important email to your manager? Fear no more! With the help of the Quick Steps feature in Outlook 2010, your old chor…
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 …
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

896 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now