PDA

View Full Version : Solved: Word document help (II)



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:

Jacob Hilderbrand
04-24-2005, 05:17 PM
If you are talking about the symbol that looks like a backwards P then that is for a new paragraph. You can show or not show those marks from Options in Word (Tools | Options | View). Or are you talking about something else?

To apply similar formatting to several paragraphs you could create a loop.


For i = 4 to 10

With .ActiveDocument.Paragraphs(i)
.Range.Font.Size = 12
.Range.Font.Bold = False
.Alignment = wdAlignParagraphLeft
End With

Next i

Mr Doubtfire
04-25-2005, 06:18 AM
Thank you. You DO always take care of me.

The symbol I have is like a square, which I think is a "Carriage return".
One of my questions is I would like to put that image on top of the page.
Could you help too!?
Thanks again.:friends:

Killian
04-25-2005, 07:00 AM
You're "square" character is ASCII code 3 you insert here.Selection.TypeText Text:=Chr(3)I think you might mean Chr(13) which is a carriage return.

Other than that, it seems to work (unless your VB clipboard assignment or the Word paste is failing?)

Mr Doubtfire
04-25-2005, 08:11 AM
Killian,

Again, you're killing me.

Any idea I could move the picture to the top of the page?

Thanks.

Killian,

It works!
Could anyone help me out to move the image to the top of the page?
Thanks guys!:clap:

Killian
04-25-2005, 08:28 AM
Is it not at the top of the page now? It's the first thing into a new document so it should be.
Unless you want to place it more specifically... the standard paste will place the picture as an "Inline" shape, meaning it's in line with the text. If you want to move it around you'll have to use pastespecial and the FloatOverText placement argumentSelection.PasteSpecial False, False, wdFloatOverText, False, wdPasteBitmapthen you can move it around with it's Left and Top properties

Mr Doubtfire
04-25-2005, 08:45 AM
Thanks. You're right I did place at the "original" top of the page.

But how could I reset the top margin?
Thanks.

MOS MASTER
04-26-2005, 11:25 AM
Hi, :D

Not quit sure what you mean but do you mean the white space is missing at the top off the page?

If so go to: Tools/Options/view/Check: "White space between pages (Print view only)

Enjoy! :thumb

Mr Doubtfire
04-26-2005, 12:49 PM
Could anyone tell me how to reset the top margin to higher so that I could save more space because of the insertion of logo at the top left?
Thanks!

MOS MASTER
04-26-2005, 12:54 PM
ActiveDocument.PageSetup.TopMargin = CentimetersToPoints(4) 'or a value you like 5, 6, etc..

Mr Doubtfire
04-26-2005, 04:43 PM
Yeh! Thank you to ALL!

MOS MASTER
04-27-2005, 10:49 AM
You're welcome! :thumb