Results 1 to 11 of 11
  1. #1
    Star Lounger
    Join Date
    Mar 2001
    Location
    New York, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variant Font Problem

    I am experienced in Excel VBA but have little experience in Word. I am stuck on a project where I want to print an envelope with a return address. The first line needs to be a different font than the envelope setup font. I can get the array but can't seem to figure out how to change RtnEnvAdd(1) to another font.

    idx = 1
    With Selection.Find
    .ClearFormatting
    .Style = ActiveDocument.Styles("Envelope Return")
    Do While .Execute(FindText:="", Forward:=True, Format:=True) = True
    For Each Paragraph In .Parent.Paragraphs
    RtnEnvAdd(idx) = Selection.Text
    idx = idx + 1
    Next
    Loop
    End With

    This is where I need some code to work with RtnEnvAdd(1)

    Any help would be appreciated.

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Variant Font Problem

    Have you tried :-
    For Each Paragraph In .Parent.Paragraphs
    RtnEnvAdd(idx) = Selection.Text
    If idx = 1 then
    Selection.Font.Name = "FontName"
    idx = idx + 1
    End If
    Next

    where Fontname is the font you want to use

  3. #3
    Star Lounger
    Join Date
    Mar 2001
    Location
    New York, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variant Font Problem

    Andrew,

    I tried that but it doesn't change the font for the return address. Font format stays as style setup. Don't think I am on the right track. Thinking about going to some sort of AutoText use?

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variant Font Problem

    Hi Thom:

    I can't help you directly with macros, as I don't know them. However, have you thought of saving the return address as an AutoText entry. You can use a formatted Autotext entry in an envelope dialog box. There must be a way to put that in your macro.

    Hope this helps.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Variant Font Problem

    This scenario is a bit unclear to me. You are reading styled text into an array - and then what is the next step? If you are feeding the plaintext in an array into Word's envelope feature, and Word is applying the "Envelope Return" style to it, you probably are at Word's mercy. Of course you could change the style like this:

    With ActiveDocument.Styles("Envelope Return").Font
    .Name = "Century Schoolbook"
    .Size = 10
    End With

    However, if you are saying that you want to apply two different types of formatting when Word is applying a single style, I don't see how you can do it without embedding printer codes. Which I never learned.

    What exactly is going on?

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Variant Font Problem

    Hi,

    Echoing Jefferson's comments: it looks like you're storing various separate text elements into an array.
    By saving them as "Selection.Text" you will lose any formatting that may have been applied to them previously.

    What you're not specifying in your posted sample, is what you're then subsequently doing to "paste" the contents of the array in as text for the envelope.

    What needs to be done is: the text that corresponds to RtnEnvAdd(1) needs to be selected (or addressed as a range), and then the font property can be adjusted. Exactly what would be the best way to select this text depends on what methods you're using to insert it into the envelope - could you post the relevant part of your code?

    In the meantime, here's some non-tested code (to paste the address array into the envelope):

    <pre>For n = 1 to UBound(RtnEnvAdd)
    Selection.TypeText RtnEnvAdd(n)
    If n = 1 Then Selection.Paragraphs(1).Range.Font = "AlternativeFontName"
    End If
    Selection.TypeText vbCrLf
    Next n</pre>


  7. #7
    Star Lounger
    Join Date
    Mar 2001
    Location
    New York, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variant Font Problem

    Here is the entire code. It is RtnEnvAdd(1) that I want to be able to change font properties. For clarification, I don't want to change the document in any way. I just want to be print an envelope with the data I have collected with a change to the first line on the return address font.

    Sub MakeEnvelope()

    Dim EnvAdd(5) As String
    Dim RtnEnvAdd(3) As String
    Dim addr As String
    Dim rtnaddr As String

    ' go to beginning of document
    Selection.HomeKey Unit:=wdStory

    idx = 1
    With Selection.Find
    .ClearFormatting
    .Style = ActiveDocument.Styles("Envelope Address")
    Do While .Execute(FindText:="", Forward:=True, Format:=True) = True
    For Each Paragraph In .Parent.Paragraphs
    EnvAdd(idx) = Selection.Text
    idx = idx + 1
    Next
    Loop
    End With

    addr = EnvAdd(1) & EnvAdd(2) & EnvAdd(3) & EnvAdd(4)

    Selection.HomeKey Unit:=wdStory

    idx = 1
    With Selection.Find
    .ClearFormatting
    .Style = ActiveDocument.Styles("Envelope Return")
    Do While .Execute(FindText:="", Forward:=True, Format:=True) = True
    For Each Paragraph In .Parent.Paragraphs
    RtnEnvAdd(idx) = Selection.Text
    If idx = 1 Then
    Selection.Font.Name = "Times New Roman"
    Else

    End If
    idx = idx + 1
    Next
    Loop
    End With


    rtnaddr = RtnEnvAdd(1) & RtnEnvAdd(2) & RtnEnvAdd(3)

    ActiveDocument.Envelope.PrintOut ExtractAddress:=False, OmitReturnAddress _
    :=False, ReturnAddress:=rtnaddr, PrintBarCode:=False, _
    PrintFIMA:=False, Height:=InchesToPoints(4.125), Width:=InchesToPoints(9.5), _
    Address:=addr, AutoText:="", ReturnAutoText:="", AddressFromLeft:=InchesToPoints(1.5), _
    AddressFromTop:=wdAutoPosition, ReturnAddressFromLeft:=InchesToPoints( _
    1.5), ReturnAddressFromTop:=wdAutoPosition, DefaultOrientation:= _
    wdCenterLandscape, DefaultFaceUp:=True

    Selection.HomeKey Unit:=wdStory
    Erase EnvAdd()
    Erase RtnEnvAdd()

    End Sub

  8. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Variant Font Problem

    I replaced
    <font color=448800>
    idx = 1
    With Selection.Find
    .ClearFormatting
    .Style = ActiveDocument.Styles("Envelope Return")
    Do While .Execute(FindText:="", Forward:=True, Format:=True) = True
    For Each Paragraph In .Parent.Paragraphs
    RtnEnvAdd(idx) = Selection.Text
    If idx = 1 Then
    Selection.Font.Name = "Times New Roman"
    Else

    End If
    idx = idx + 1
    Next
    Loop
    End With
    </font color=448800>
    with
    <font color=448800>
    Dim rngSel As Word.Range

    Set rngSel = ActiveWindow.Document.Paragraphs.First.Range
    rngSel.Select
    Selection.Font.Name = "Times New Roman"
    </font color=448800>
    and it seems to work

    I just happen to find a document with something similar, so hope it helps you.

    Andrew

  9. #9
    Star Lounger
    Join Date
    Mar 2001
    Location
    New York, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variant Font Problem

    Andrew,

    That will change the document. I don't want to change the document. I just want to change the variable font and print the envelope as I described above.

    Thank you all for your efforts.

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Variant Font Problem

    (1) I think this is a dead end. I cannot think of any way to store rich text in a variable; variants and ranges seem no better than strings in this regard. Rich text can be stored in an AutoText entry, but I cannot think of any way to feed the rich text of an AutoText entry to the .PrintOut method.

    (2) The Envelopes and Labels dialog contains rich text edit controls, so you could kludge this together with SendKeys. But I know you are avoiding that on purpose.

    (3) I think it is time to code-your-own alternative to .PrintOut (or find a COM add-in that does it). One VBA solution would be to create an envelope template that is the right shape and size and has two text boxes or frames to position your data. You then could use standard VBA to type in the text and style it prior to printing. This document need not appear on screen, and could have the PageSetup settings of your choice.

    (4) A twist on (3) would be to throw the data into a tab-separated text file, create your template as a master merge document, and generate all the envelopes in one go using a merge. Not being a merge guru, I can't say for sure that this would give the best results, but the formatting would be very easy to set up, and you wouldn't have as much coding overhead. Also, you could leave the user with the merge document in case he/she needs to print part of it again.

  11. #11
    Star Lounger
    Join Date
    Mar 2001
    Location
    New York, USA
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Variant Font Problem

    Thanks to all!

    What I ended up doing was to add a document, insert an envelope, and yes needed to use RichText to keep formatting, print it and then close the extra document. Should be some better ways but for now this will work.

Posting Permissions

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