Consulting

Results 1 to 2 of 2

Thread: Excel to word

  1. #1
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    Excel to word

    This has me stumped

    I am using this to try and send some data from excel to word

    The word document template has a bookmark named "customer" nothing else at all

    but i get an error message
    "Name" is read only property

    What am I doing wrong?
    (answer is probably using MSword )

    [vba]Sub BuildQuote()
    Dim customer As String
    Dim oWord As Object, oDoc As Object
    Dim fPath As String
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("TblQuoteLine")
    fPath = "C:\Demo.dot"
    Set oWord = CreateObject("Word.Application")
    Set oDoc = oWord.Documents.Open(fPath)
    customer = "Fred"
    With oDoc
    .bookmarks("customer") = customer
    End With
    'close objects
    Set oWord = Nothing
    Set oDoc = Nothing
    End Sub[/vba]

  2. #2
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    This seems to work

    [vba]With oWord.ActiveDocument
    .Bookmarks("customer").Range.Text = customer
    end with[/vba]

    Why dont I get any prompts though when trying to write the code?

Posting Permissions

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