Sættes ind i Form1
----------------------------------------------
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Dim Hay As Object 'Object
' Resume to the next line following the error.
On Error Resume Next
' Attempt to reference Word which is already running.
Set Hay = GetObject(, "Word.Application")
' If true, Word is not running.
If Hay Is Nothing Then
' Create a new instance of the Word application.
'Set Hay = New Word.Application
'late binding for hebrew
Set Hay = CreateObject("Word.Application")
' If true, MS Word 8.0 is not installed.
If Hay Is Nothing Then
MsgBox "MS Word 8.0 is not installed on your computer"
Exit Sub
End If
End If
On Error GoTo ErrHandler
Hay.Visible = True
Hay.Documents.Add
If WordHide = False Then
Hay.ActiveWindow.View.Type = wdNormalView
Hay.Application.WindowState = wdWindowStateMaximize
End If
z = 1
With Hay
If HebWord = True Then 'Hebrew
z = 991
.Selection.LtrPara
z = 1
Else
If .Selection.ParagraphFormat.Alignment <> wdAlignParagraphLeft Then
.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
End If
End If
z = 999
'pagenum
.Selection.Sections(1).Footers(1).PageNumbers.Add
PageNumberAlignment:=wdAlignPageNumberCenter, FirstPage:=False
z = 11
'''''''''''''''''''''''''''Header''''''''''''''''''''''''''''''''''''
.Selection.Font.Size = 14
Header Hay
.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
''''''end header
SavingFile = (App.Path & "\MyDoc.doc")
End With
'save
Hay.ActiveDocument.SaveAs FileName:=SavingFile,
FileFormat:=wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False,
SaveFormsData:=False, SaveAsAOCELetter:=False
If MsgBox("Print ?", vbYesNo) = vbYes Then
Hay.ActiveDocument.PrintOut
Sleep (3000)
Hay.Application.WindowState = wdWindowStateMinimize
MsgBox "The Report is ready, please wait while Word printing."
Hay.ActiveDocument.Close wdDoNotSaveChanges
DoEvents
Else
Hay.ActiveDocument.Close wdSaveChanges
End If
MsgBox "unloading word"
Hay.Visible = False
Hay.Application.Quit
Set Hay = Nothing
Exit Sub
ErrHandler:
MsgBox "Error - " & Format(Err.Number) & " - " & Format(Err.Description)
& " in Word_format phase - " & Str$(z)
End Sub
Public Sub Header(Hay As Word.Application)
'write heder to word document
On Error GoTo ErrHandler
With Hay
.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Selection.TypeText Text:=Chr$(13) & Chr$(13) & Chr$(13) & Chr$(13)
.Selection.TypeText Text:=Chr$(13) & Chr$(13) & Chr$(13) & Chr$(13)
.Selection.Font.Size = 24
.Selection.Font.Bold = wdToggle
' If HebWord = True Then
' .Selection.Font.BoldBi = wdToggle
' End If
.Selection.TypeText Text:=HeaderComp & Chr$(13) & Chr$(13)
.Selection.Font.Size = 18
.Selection.TypeText Text:="Cool Stuff" & Chr$(13) & Chr$(13)
.Selection.TypeText Text:="By Fun Factory" & Chr$(13) & Chr$(13)
.Selection.Font.Bold = wdToggle
' If HebWord = True Then
' .Selection.Font.BoldBi = wdToggle
' End If
.Selection.TypeText Text:="First Page" & Chr$(13) & Chr$(13)
.Selection.TypeText Text:="Presented To: U" & Chr$(13) & Chr$(13)
.Selection.TypeText Text:="Enjoy" & Chr$(13)
.Selection.TypeText Text:=Chr$(13) & Chr$(13)
.Selection.TypeText Text:=Format(FormatDateTime(Date, 1))
.Selection.WholeStory
'border lines
.Selection.Borders(wdBorderTop).LineStyle =
..Options.DefaultBorderLineStyle
.Selection.Borders(wdBorderTop).LineWidth =
..Options.DefaultBorderLineWidth
.Selection.Borders(wdBorderTop).ColorIndex =
..Options.DefaultBorderColorIndex
.Selection.Borders(wdBorderLeft).LineStyle =
..Options.DefaultBorderLineStyle
.Selection.Borders(wdBorderLeft).LineWidth =
..Options.DefaultBorderLineWidth
.Selection.Borders(wdBorderLeft).ColorIndex =
..Options.DefaultBorderColorIndex
.Selection.Borders(wdBorderBottom).LineStyle =
..Options.DefaultBorderLineStyle
.Selection.Borders(wdBorderBottom).LineWidth =
..Options.DefaultBorderLineWidth
.Selection.Borders(wdBorderBottom).ColorIndex =
..Options.DefaultBorderColorIndex
.Selection.Borders(wdBorderRight).LineStyle =
..Options.DefaultBorderLineStyle
.Selection.Borders(wdBorderRight).LineWidth =
..Options.DefaultBorderLineWidth
.Selection.Borders(wdBorderRight).ColorIndex =
..Options.DefaultBorderColorIndex
.Selection.MoveRight Unit:=wdCharacter, Count:=1
.Selection.InsertBreak Type:=wdPageBreak
.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
' GoTo endofloop
.Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Selection.Font.Size = 14
.Selection.Font.Bold = 0
' If HebWord = True Then
' .Selection.Font.BoldBi = 0
' End If
End With
Exit Sub
ErrHandler:
MsgBox "Error - " & Format(Err.Number) & " - " & Format(Err.Description)
& " in header."
End Sub
----------------------------------
http://webtime.adr.dk
----------------------------------
"BT" <brian.toft.remove.this@get2net.dk> skrev i en meddelelse
news:3dbd98b6$0$34828$edfadb0f@dspool01.news.tele.dk...
> Hej NG..
>
> Jeg har lavet et lille program som modtager nogle data fra et måle
apperat..
>
> Nu er mit problem bare, at jeg gerne vil have disse data'er over i et
> standart word-dokument, for at printe det ud senere..
>
> Er der nogen der ved hvordan det gøres...
>
> Brian
>
>