Solved

Word Automation - paragraphs and bullets

Posted on 2001-08-13
15
985 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

708 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

20 Experts available now in Live!

Get 1:1 Help Now