Word Automation

  • Thread starter Thread starter scorpion53061
  • Start date Start date
S

scorpion53061

My boss is more and more asking me to get into areas of report formatting
and such with the primarily database apps that I write.

I am not pleased with Crystal and some of the pitfalls I have seen with this
particualar report tool.

I would like to delve into Word automation ( I believe you can control page
breaks and such with this). Can someone point me to a good how to with the
various methods available there?
 
Check the "Microsoft Word Visual Basic" reference in the Microsoft Word
Help, under "Programming Information" in the contents.
 
I don't like the implementation of Crystal in VS.NET only b/c of the lack of
a preview feature...but as far as Page Breaks and the rest...you can
definitely do it with Crystal. Mastering Visual Basic.NET by Sybex has a
pretty good section on Word automation, but be forewarned, it can be quite
slow compared to running standard word macros. We had a few in both Excel
and word that exectued in a few seconds in either the Word or Excel
environment, ported the exact code to .NET and it ran much slower, sometimes
as long as a few minutes to do what executed in a few seconds.

Component One has a product called Active Reports that's free right now and
I've used to it with a good deal of satisfaction. However, I wouldn't write
off Crystal Reports just yet...it's probably the best report writer on the
market.

HTH,

Bill
 
Hi scorpion53061, till MS rewrites OFFICE in dotnet and provides a dotnet
interface for automating, it is best to stick to VBA or compiled VB6 code
( I would prefer the latter). We do serious office integration and believe
me VB6 is the best option.
 
Thank you for the input........
I find it quite strange that MS does not make their own products friendly in
their development environment.
 
I will look for this active reports software.

I didn't fault Crystal for its ability in writing. However I have noticed
that when I used it with apps just here in this office I noticed windows
stability issues (especially 2000) that were difficult to understand
(crashing, certain dll files caused problems)
 
well one day for about an hour and a half it was pretty slow so I decided to
give this a shot.
It is pathetic admittedly. But hey got to start somewhere.

If anyone can advise me of how to actually get this data into word please
let me know....

Private Sub FillIN()
Dim wordApp As Word.Application
wordApp = CreateObject("Word.Application")
Dim wordDoc As Word.Document
Dim wordRng As Word.Range
Dim wordPara As Word.Paragraph
Dim wordRng1 As Word.Range
Dim wordPara2 As Word.Paragraph
With WordApp
.WindowState = Word.WdWindowState.wdWindowStateMaximize
.Documents.Add()
wordApp.Visible = True
wordDoc = wordApp.ActiveDocument
wordRng = wordDoc.Range
wordRng1 = wordDoc.Range
With wordRng
.Font.Bold = True
.Font.Italic = True
.Font.Size = 14

.InsertAfter("Invoice - Customer 252991")
.InsertParagraphAfter()
End With
wordPara = wordRng.Paragraphs.Item(3)
With wordPara.Range
.Bold = False
.Italic = True
.Font.Size = 14
End With
With wordRng1
.Font.Bold = True
.Font.Italic = False
.Font.Size = 13
paragraphcount = 0
Dim i, r, c As Integer
For i = 0 To Stock11.Tables.Count - 1
'.Tables.Add(wordRng1, 1, c)
For c = 0 To Stock11.Tables(i).Columns.Count - 1
.InsertAfter(Stock11.Tables(i).Columns(c).ColumnName
& vbTab)
Next
For r = 0 To Stock11.Tables(i).Rows.Count - 1
'.InsertParagraphAfter()
'.Rows.Add(r)
For c = 0 To Stock11.Tables(i).Columns.Count - 1
.InsertAfter(Stock11.Tables(i).Rows(r).Item(c) &
vbTab)
'.InsertParagraphAfter()
Next
.InsertParagraphAfter()
paragraphcount = paragraphcount + 1
Next
Next

paragraphcount = paragraphcount + 1
.InsertAfter("Customer 252991")
.InsertParagraphAfter()
' Insert a blank paragraph between the two paragraphs.
.InsertParagraphAfter()
paragraphcount = paragraphcount + 2
wordPara2 = wordRng1.Paragraphs.Item(paragraphcount)

With wordPara2.Range

.Bold = True
.Italic = False
.Font.Size = 13
End With
End With
End With


'.ActiveDocument.SaveAs("c:\test\test.Doc")
'.ActiveDocument.Saved = True
'.Quit()

End Sub
 
I mean get it into a table in word.......right now it is tabbing between
columns. When I tried to write the table (.Tables.Add(r,c) it wiped out the
contents of the page and bombed.
 
Back
Top