Solved

Word Automation - paragraphs and bullets

Posted on 2001-08-07
14
627 Views
Last Modified: 2012-05-04
I'm using Excel '97 to produce a report in Word '97. I'm exporting data from the Excel file to the report. The main difficulty I'm having understanding the InsertAfter statements and exactly how to just put some text at the end of the current document or format the text which I've just inserted. For example, I want to loop through a cloumn of cells until they are blank, putting the contents of each cell as a new paragraph, sequencially and each one of them with a Bulletpoint:

dim wordapp as word.application
dim worddoc as word.document
Set wordapp = CreateObject("Word.Application")
Wordapp.Documents.Add
Set WordDoc = wordapp.ActiveDocument
do while Trim(Range(Chr(intRow +65) & 1)).Value <> ""
WordDoc.Content.MoveEnd

WordDoc.Content.InsertAfter Worksheets("Sheet1").Range(Chr(intRow+65 &65).value

'some code which will put a formatted bulletinfront of the above?

loop

Please state if clarifcation is required....
Any comments greatly appreciated.
0
Comment
Question by:robertsmith28
  • 7
  • 4
  • 3
14 Comments
 

Author Comment

by:robertsmith28
ID: 6359585
oops, forgot to add some bits into the loop

introw = 1
do while...
..
..
..
..
intRow = intRow + 1
Loop
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6359622
Hi robert,

I posted a question in the MS Office topic area for you, pointing to this one.

Nosterdamus
0
 

Author Comment

by:robertsmith28
ID: 6359651
Nosterdamus,
Thanks - so have I - did n't realise which area I was in - oops!
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6359659
Should I delete my link question?
0
 

Author Comment

by:robertsmith28
ID: 6359727
Actually it was my other misplaced question! Thanks - just leave I reckon.
0
 
LVL 17

Accepted Solution

by:
calacuccia earned 100 total points
ID: 6359861
Hi Robert (thanks Noster for leading me here)

The easiest way to work around in Word documents is to use the Selection object, which is a objet from the Word.APplication object. First apply the formatting to the selection, then type some text, then put a paragraph mark, and so on...

example (I found some minor syntax problems in your code)

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(Range(Chr(intRow + 65) & 3).Value) <> ""
wordapp.Selection.EndKey wdStory 'This will make the selection (or the cursor) go
                                  'to the end of the document
wordapp.Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
        wdBulletGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _
        wdListApplyToWholeList
wordapp.Selection.TypeText Worksheets("Sheet1").Range(Chr(intRow + 65) & 4).Value 'Type text from Excel in selection (cursor)
wordapp.Selection.TypeParagraph 'Enter a paragraphs mark, cursor or selection will go to next paragraph
'some code which will put a formatted bulletinfront of the above?
intRow = intRow + 1

Loop


Hope this helps
calacuccia
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 6359867
P.S. I changed the Chr(IntRow + 65) & 3 a little to match my sample sheet I was working on.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6359884
Hi cal,

Nice to see you again... ;-)

Nosterdamus
0
 

Author Comment

by:robertsmith28
ID: 6360039
calacuccia,
That looks great - I'll just try to implement it - back in an hour or two...
Rob.
0
 

Author Comment

by:robertsmith28
ID: 6360374
calacuccia,
That looks great - I'll just try to implement it - back in an hour or two...
Rob.
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6360397
Hi Rob,

Just a hint. to avoid multiple postings, use the Reload Question link at the top of the page, instead of hitting the Browser's reload button.

Nosterdamus
0
 

Author Comment

by:robertsmith28
ID: 6360769
Thanks calacuccia, as always, was exactly what I was looking for - excellent!
0
 
LVL 17

Expert Comment

by:calacuccia
ID: 6362860
ThAnks, robert.

Regards
calacuccia
0
 

Author Comment

by:robertsmith28
ID: 6364251
calacuccia,
this one's also in the wrong area for 70 - FYI.

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=msaccess&qid=20164520
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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

930 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

11 Experts available now in Live!

Get 1:1 Help Now