+ Reply to Thread
Results 1 to 9 of 9

Want to have data linkefrom excel into a word document in a certain way, is this possible?

Hybrid View

  1. #1
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Want to have data linkefrom excel into a word document in a certain way, is this possi

    You could get word to pull but, from a personal point of view, writing VBA in Excel is easier that in Word.

    I would suggest that any Excel 'push' code is lcated in a separate workbook so all you need is to read from the restricted weekly sheet.

    I've attached a couple of files.

    Save the Word file to c:\temp

    Then run the Test macro in the workbook.

    The code creates a Word application, opens the template and substitutes three values. I've made a reference to the Word 14 object library. (VBA editor - tools - references)

    Dim WordApp As Word.Application
    Dim WordDoc As Word.Document
    
    
    Sub Test()
    Set WordApp = New Word.Application
    Set WordDoc = WordApp.Documents.Open("C:\temp\template.docx")
    WordApp.Visible = True
    
    With WordApp.Selection.Find
        .Text = "#A1#"
        .Replacement.Text = Range("A1")
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    WordApp.Selection.Find.Execute Replace:=wdReplaceAll
    
    With WordApp.Selection.Find
        .Text = "#B1#"
        .Replacement.Text = Range("B1")
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    WordApp.Selection.Find.Execute Replace:=wdReplaceAll
    
    With WordApp.Selection.Find
        .Text = "#C1#"
        .Replacement.Text = Range("C1")
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    WordApp.Selection.Find.Execute Replace:=wdReplaceAll
    
    End Sub
    Attached Files Attached Files
    Martin

  2. #2
    Registered User
    Join Date
    10-19-2013
    Location
    United Kingdom
    MS-Off Ver
    MS office 2003
    Posts
    25

    Re: Want to have data linkefrom excel into a word document in a certain way, is this possi

    Quote Originally Posted by mrice View Post
    You could get word to pull but, from a personal point of view, writing VBA in Excel is easier that in Word.

    I would suggest that any Excel 'push' code is lcated in a separate workbook so all you need is to read from the restricted weekly sheet.

    I've attached a couple of files.

    Save the Word file to c:\temp

    Then run the Test macro in the workbook.

    The code creates a Word application, opens the template and substitutes three values. I've made a reference to the Word 14 object library. (VBA editor - tools - references)

    Dim WordApp As Word.Application
    Dim WordDoc As Word.Document
    
    
    Sub Test()
    Set WordApp = New Word.Application
    Set WordDoc = WordApp.Documents.Open("C:\temp\template.docx")
    WordApp.Visible = True
    
    With WordApp.Selection.Find
        .Text = "#A1#"
        .Replacement.Text = Range("A1")
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    WordApp.Selection.Find.Execute Replace:=wdReplaceAll
    
    With WordApp.Selection.Find
        .Text = "#B1#"
        .Replacement.Text = Range("B1")
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    WordApp.Selection.Find.Execute Replace:=wdReplaceAll
    
    With WordApp.Selection.Find
        .Text = "#C1#"
        .Replacement.Text = Range("C1")
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    WordApp.Selection.Find.Execute Replace:=wdReplaceAll
    
    End Sub
    Thanks for your help! Can't access those at the moment since im using a mac and it doesnt seem to happy with it, but will give it a go when i get on a windows computer!

    Could you clarify what you mean by "so all you need is to read from the restricted weekly sheet" could you clarify what you mean by this? (Sorry to be a pain! All of this is quite new to me!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. copy data from excel and paste the data to word document in speciofic column.
    By vsabap in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-17-2012, 07:12 AM
  2. Link Excel Data to a Word document
    By cory_0101 in forum Excel General
    Replies: 0
    Last Post: 09-27-2012, 11:43 AM
  3. [SOLVED] how can I import excel data to word document
    By powersree in forum Excel General
    Replies: 1
    Last Post: 10-09-2005, 08:05 PM
  4. Transferring Excel Data to Word Document
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2005, 03:05 AM
  5. Transferring Excel Data to Word Document
    By maacmaac in forum Excel General
    Replies: 0
    Last Post: 10-06-2005, 12:23 PM

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.6.0 RC 1