PDA

View Full Version : Change cell colour and copy cell format over to word



thedark123
06-20-2006, 07:37 AM
I just wan to do some preformat to some of the selected cells, like to change its cell colour font type etc. and copy all those formatted and selected over to word...previously the one that I need to do in a word template was too tricky..

Any I got this code which copies cells over from excel and by using bookmark to paste it correctly to the correct position in a table in word.

Sub createWordReport()
On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Dim companyName As Excel.Range
Dim yearEnd As Excel.Range

Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add(Template:="C:\Documents and Settings\ _
User\Desktop\today latest 123\format\testnew.dot")
Set companyName = Sheets("Sheet1").Range("A7")
Set yearEnd = Sheets("Sheet1").Range("C7")
With myDoc.Bookmarks
.Item("CompanyName").Range.InsertAfter companyName
.Item("YearEnd").Range.InsertAfter yearEnd
End With
errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing
End Sub

lucas
06-20-2006, 07:47 AM
Background on this post:
http://vbaexpress.com/forum/showthread.php?t=8466
http://vbaexpress.com/forum/showthread.php?t=8463
http://vbaexpress.com/forum/showthread.php?t=8459
http://vbaexpress.com/forum/showthread.php?t=8359