Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Export excel data to word document | Excel Discussion (Misc queries) | |||
Linking excel data to a word document | Excel Discussion (Misc queries) | |||
Transferring Excel Data to Word Document | Excel Programming | |||
Transferring Excel Data to Word Document | Excel Discussion (Misc queries) | |||
Creating a Word Document from Excel Data | Excel Programming |