Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default writing excel data into word document

I want to create report in Word using data from excel. I have problems with writing several paragraphs, one after the other, starting after bookmark created in word templates. In my code it is writing in reverse order and I would like to change it. In addition I would like to add paragraph styles after inserting each paragraph. How I should change my code ?

Thanks for help / suggestions.

Sub CreateWordReport()

Dim applWord As Object

TodaysDate = Format(Date, "dd mmm, yyyy")

'Create a new instance of the Word application, if an existing Word object is not available.
'Set the Application object as follows:
On Error Resume Next
Set applWord = GetObject(, "Word.Application")
'if an instance of an existing Word object is not available, an error will occur (Err.Number = 0 means no error):
If Err.Number < 0 Then
Set applWord = CreateObject("Word.Application")
End If
'disable error handling:
On Error GoTo 0

'make the Word window visible:
applWord.Visible = True

'add a new word document:
applWord.Documents.add Template:="G:\Template\RTS Flash - Template.dotx", _
NewTemplate:=False, DocumentType:=0

'to save document in the default folder:
NewFileName = "c:\temp\Flash Report " & TodaysDate & ".docx"
applWord.ActiveDocument.SaveAs Filename:=NewFileName

With ActiveDocument
.Bookmarks("MajorIssuesStart").Range.InsertAfter "Inserted Text"
.Bookmarks("MajorIssuesStart").Range.InsertAfter Chr(13)
.Bookmarks("MajorIssuesStart").Range.InsertAfter "Second Inserted Text"
.Bookmarks("MajorIssuesStart").Range.InsertAfter Chr(13)
.Bookmarks("MajorIssuesStart").Range.InsertAfter "Third Inserted Text"
End With

'clear the object variables:
Set applWord = Nothing

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default writing excel data into word document

Couple of suggestions:

This code 1st tries to 'hijack' a running instance of Word (very bad
practice) instead of using its own automated instance from the start. I
recommend you just go with CreateObject()!

What are you using Word for that you can't just use a blank worksheet
in Excel for your report? (I've never found anything Word can do that
can't be duplicated in Excel!!!) You can use a template sheet and just
populate it with your data laid out in the report format.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export excel data to word document mda19652 Excel Discussion (Misc queries) 1 November 1st 07 12:01 PM
Linking excel data to a word document Hutchy Excel Discussion (Misc queries) 0 May 16th 07 08:46 AM
Transferring Excel Data to Word Document maacmaac Excel Programming 1 October 7th 05 07:38 AM
Transferring Excel Data to Word Document maacmaac Excel Discussion (Misc queries) 0 October 6th 05 05:23 PM
Creating a Word Document from Excel Data Sheldon Excel Programming 1 September 15th 04 10:10 PM


All times are GMT +1. The time now is 05:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"