Results 1 to 12 of 12

Thread: Solved: Word document help (II)

  1. #1

    Solved: Word document help (II)

    The following code was an answer that I received from my previous solved "Word document help" with new additions.

    [VBA] 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[/VBA]


    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.

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    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.

    [vba]
    For i = 4 to 10

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

    Next i
    [/vba]

  3. #3
    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.

  4. #4
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    You're "square" character is ASCII code 3 you insert here[VBA].Selection.TypeText Text:=Chr(3)[/VBA]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?)
    K :-)

  5. #5
    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!

  6. #6
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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 argument[VBA]Selection.PasteSpecial False, False, wdFloatOverText, False, wdPasteBitmap[/VBA]then you can move it around with it's Left and Top properties
    K :-)

  7. #7
    Thanks. You're right I did place at the "original" top of the page.

    But how could I reset the top margin?
    Thanks.

  8. #8
    Administrator
    VP-Knowledge Base VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    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!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  9. #9
    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!

  10. #10
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    [VBA]ActiveDocument.PageSetup.TopMargin = CentimetersToPoints(4) 'or a value you like 5, 6, etc..[/VBA]
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  11. #11
    Yeh! Thank you to ALL!

  12. #12
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    You're welcome!
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •