+ Reply to Thread
Results 1 to 2 of 2

Thread: Format word created from Excel VBA

  1. #1
    eran.chason@gmail.com
    Guest

    Format word created from Excel VBA

    Hello,
    I have the following code to create word from excel VBA. I cant find a
    way to formatsome of the text with BOLD or font size. Any help will be
    great!

    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document
    Dim i As Integer
    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = False
    Set wrdDoc = wrdApp.Documents.Add ' create a new document

    With wrdDoc

    .Content.InsertAfter "Date " & Me.DTPicker1.Value & vbCr & vbCr

    ' How to format font ????

    ..Content.InsertAfter vbTab & "^B Return Material Authorization" & vbCr
    & vbCr
    .SaveAs Range("Info!G2").Text & "\RMA report for " &
    Me.TextBox17_PartNumber & ".doc"
    .Close ' close the document
    End With

    wrdApp.Quit ' close the Word application

    Set wrdDoc = Nothing
    Set wrdApp = Nothing


    Thanls!!!

    Eran


  2. #2
    Jim Thomlinson
    Guest

    RE: Format word created from Excel VBA

    You did not specify which font so here is a simple example setting the font
    to bold. I changed the create object to just instantiating a new instance of
    word since you referenced the Word library anyway...

    Sub Test()
    Dim wrdApp As Word.Application
    Dim wrdDoc As Word.Document

    Set wrdApp = New Word.Application
    wrdApp.Visible = True
    Set wrdDoc = wrdApp.Documents.Add ' create a new document

    With wrdDoc
    .Characters(1).Font.Bold = wdToggle
    .Content.InsertAfter "Date " & vbCr & vbCr

    ' How to format font ????

    .Close ' close the document
    End With

    wrdApp.Quit ' close the Word application

    Set wrdDoc = Nothing
    Set wrdApp = Nothing

    End Sub
    --
    HTH...

    Jim Thomlinson


    "eran.chason@gmail.com" wrote:

    > Hello,
    > I have the following code to create word from excel VBA. I cant find a
    > way to formatsome of the text with BOLD or font size. Any help will be
    > great!
    >
    > Dim wrdApp As Word.Application
    > Dim wrdDoc As Word.Document
    > Dim i As Integer
    > Set wrdApp = CreateObject("Word.Application")
    > wrdApp.Visible = False
    > Set wrdDoc = wrdApp.Documents.Add ' create a new document
    >
    > With wrdDoc
    >
    > .Content.InsertAfter "Date " & Me.DTPicker1.Value & vbCr & vbCr
    >
    > ' How to format font ????
    >
    > ..Content.InsertAfter vbTab & "^B Return Material Authorization" & vbCr
    > & vbCr
    > .SaveAs Range("Info!G2").Text & "\RMA report for " &
    > Me.TextBox17_PartNumber & ".doc"
    > .Close ' close the document
    > End With
    >
    > wrdApp.Quit ' close the Word application
    >
    > Set wrdDoc = Nothing
    > Set wrdApp = Nothing
    >
    >
    > Thanls!!!
    >
    > Eran
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0