Hi all,
I found this code, but I can't save the WordDoc properly as I want.
Anyone knows how to do this ?
I found this code, but I can't save the WordDoc properly as I want.
Anyone knows how to do this ?
Code:
' Automation of Microsoft Word from Excel
' NOTE: There must be a reference to the current Word
' library from TOOLS | REFERENCES within the VBE
' *************************************************************
'Proc12 uses CreateObject to get the Word 97 Automation object.
'Proc12 then proceeds to create a report in a Word document,
'pasting Excel worksheet data and an Excel chart into the document.
Sub ExcelRoutines_Proc12_CreateWordReport()
'Because this module relies on late binding, it is
'necessary to declare constants to be used with PowerPoint.
Const wdWindowStateMaximize As Integer = 1
Const wdNormalView As Integer = 1
Const wdAlignParagraphCenter As Integer = 1
Const wdAnimationShimmer As Integer = 1
Const wdPasteMetafilePicture As Integer = 3
Const wdInLine As Integer = 0
Const wdPageFitFullPage As Integer = 1
Const wdGoToAbsolute As Integer = 1
Const wdGoToLine As Integer = 3
Dim WordDoc As Object
Dim Filename As String
Filename = "Bestel" & (Date) & ".doc"
Set WordApp = CreateObject("Word.Application")
With WordApp
.Visible = True
.WindowState = wdWindowStateMaximize
.Documents.Add
Set WordDoc = .ActiveDocument
End With
'next bold part isn't working, it's saving the Excel file instead of the WordDoc
[b]With WordDoc
SaveAs Filename
End With[/b]
WordDoc.ActiveWindow.View = wdNormalView
With WordApp.Selection
.InsertAfter "Hansie's VBA Code"
.InsertParagraphAfter
.InsertAfter "Automatisch Word rapport vanuit Excel!"
.InsertParagraphAfter
.InsertAfter "Je kan hier natuurlijk van alles zetten " _
& ":"
.InsertParagraphAfter
.MoveRight
End With
With WordDoc.Paragraphs(1).Range
.ParagraphFormat.Alignment = wdAlignParagraphCenter
With .Font
.Name = "Arial"
.Size = 20
.Bold = True
.Animation = wdAnimationShimmer
End With
End With
With WordDoc.Paragraphs(2).Range
With .ParagraphFormat
.SpaceAfter = 12
.Alignment = wdAlignParagraphCenter
End With
With .Font
.Name = "Arial"
.Size = 14
End With
End With
WordDoc.Paragraphs(3).Range.ParagraphFormat.SpaceAfter = 30
Range("A1:B250").Copy
With WordApp.Selection
.Paste
.TypeParagraph
End With
End Sub