Mr Doubtfire
04-24-2005, 04:07 PM
The following code was an answer that I received from my previous solved "Word document help" with new additions.
Option Explicit
Private Sub Form_Load()
Dim objApp As Word.Application
Dim strToday
Dim strCustomer
Dim strReference
Dim variable1
Set objApp = New Word.Application
strToday = Date
strCustomer = "Killian"
strReference = "Order notice"
variable1 = "blah blah"
Clipboard.Clear
Clipboard.SetData Picture1.Image, vbCFBitmap
With objApp
.Documents.Add , , , True
.Visible = False
.Selection.Paste
.Selection.TypeText Text:=Chr(3)
.Selection.TypeText Text:=strToday & vbCrLf
.Selection.TypeText Text:=strCustomer & vbCrLf
.Selection.TypeText Text:=strReference & vbCrLf
.Selection.TypeText Text:="variable1" & vbCrLf
With .ActiveDocument.Paragraphs(1)
.Range.Font.Size = 12
.Range.Font.Bold = True
.Alignment = wdAlignParagraphLeft
End With
With .ActiveDocument.Paragraphs(2)
.Range.Font.Size = 12
.Range.Font.Bold = True
.Alignment = wdAlignParagraphRight
End With
With .ActiveDocument.Paragraphs(3)
.Range.Font.Size = 12
.Range.Font.Bold = False
.Alignment = wdAlignParagraphLeft
End With
With .ActiveDocument.Paragraphs(4)
.Range.Font.Size = 14
.Range.Font.Bold = True
.Alignment = wdAlignParagraphCenter
End With
With .ActiveDocument.Paragraphs(5)
.Range.Font.Size = 12
.Range.Font.Bold = False
.Alignment = wdAlignParagraphRight
End With
End With
objApp.ActiveDocument.SaveAs FileName:="c:\test\doc1.doc"
Set objApp = Nothing
End Sub
The new questions are -
I have added a picture at the top left of each document using Clipboard and "selection.paste". It works but there is always a symbol appearing at the end of the image, which I think is "Carriage Return".
How could I eliminate the symbol and at the same time jumps a line for the next text? (chr(3) !?)
How could I move the image to the top of the document in order to save space?
The way I format is applied to each line, like line1 is left-aligned, line2 is right-aligned, and line3 is center-aligned.
What should I do if line4-10 is left-aligned and line 11-20 is font-size 10? Do I need to format them (by paragraph) one by one even some consecutive lines have same format?
Please comment.
Thanks.:friends:
Option Explicit
Private Sub Form_Load()
Dim objApp As Word.Application
Dim strToday
Dim strCustomer
Dim strReference
Dim variable1
Set objApp = New Word.Application
strToday = Date
strCustomer = "Killian"
strReference = "Order notice"
variable1 = "blah blah"
Clipboard.Clear
Clipboard.SetData Picture1.Image, vbCFBitmap
With objApp
.Documents.Add , , , True
.Visible = False
.Selection.Paste
.Selection.TypeText Text:=Chr(3)
.Selection.TypeText Text:=strToday & vbCrLf
.Selection.TypeText Text:=strCustomer & vbCrLf
.Selection.TypeText Text:=strReference & vbCrLf
.Selection.TypeText Text:="variable1" & vbCrLf
With .ActiveDocument.Paragraphs(1)
.Range.Font.Size = 12
.Range.Font.Bold = True
.Alignment = wdAlignParagraphLeft
End With
With .ActiveDocument.Paragraphs(2)
.Range.Font.Size = 12
.Range.Font.Bold = True
.Alignment = wdAlignParagraphRight
End With
With .ActiveDocument.Paragraphs(3)
.Range.Font.Size = 12
.Range.Font.Bold = False
.Alignment = wdAlignParagraphLeft
End With
With .ActiveDocument.Paragraphs(4)
.Range.Font.Size = 14
.Range.Font.Bold = True
.Alignment = wdAlignParagraphCenter
End With
With .ActiveDocument.Paragraphs(5)
.Range.Font.Size = 12
.Range.Font.Bold = False
.Alignment = wdAlignParagraphRight
End With
End With
objApp.ActiveDocument.SaveAs FileName:="c:\test\doc1.doc"
Set objApp = Nothing
End Sub
The new questions are -
I have added a picture at the top left of each document using Clipboard and "selection.paste". It works but there is always a symbol appearing at the end of the image, which I think is "Carriage Return".
How could I eliminate the symbol and at the same time jumps a line for the next text? (chr(3) !?)
How could I move the image to the top of the document in order to save space?
The way I format is applied to each line, like line1 is left-aligned, line2 is right-aligned, and line3 is center-aligned.
What should I do if line4-10 is left-aligned and line 11-20 is font-size 10? Do I need to format them (by paragraph) one by one even some consecutive lines have same format?
Please comment.
Thanks.:friends: