+ Reply to Thread
Results 1 to 2 of 2

Need to save excel table into Word document

  1. #1
    Registered User
    Join Date
    12-18-2020
    Location
    Darwin, Australia
    MS-Off Ver
    excel 2016
    Posts
    1

    Need to save excel table into Word document

    Hello,
    I have an excel document which I have created from a word document by saving as a html file and then a excel file. So that it retains the word formatting for the table. Now I want to add a Active X macro button to save it back to a word document. Currently this is my code, and it is giving me a "compile error: user defined type not defined" error.

    Private Sub CommandButton1_Click()
    Dim tblRange As Excel.Range
    Dim WordApp As Word.Application
    Dim WordDoc As Word.Document
    Dim WordTable As Word.Table
    Set tblRange = ThisWorkbook.Worksheets("CSV LOG TEMPLATE").Range("B2:L169")
    On Error Resume Next
    Set WordApp = GetObject(class:="Word.Application")
    If WordApp Is Nothing Then Set WordApp = CreateObject(class:="Word.Application")
    WordApp.Visible = True
    WordApp.Activate
    Set WordDoc = WordApp.Documents.Add
    tblRange.Copy
    WordDoc.Paragraphs(1).Range.PasteExcelTable _
    LinkedToExcel:=False, _
    WordFormatting:=False, _
    RTF:=False
    Set WordTable = WordDoc.Tables(1)
    WordTable.AutoFitBehavior (wdAutoFitWindow)
    End Sub

    Any help would be appreciated to get it running.


    Thanks,

    Jana

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Need to save excel table into Word document

    Welcome to the forum,

    Please Login or Register  to view this content.
    or add reference to:
    "Microsoft Word xx.x Object Library"

+ 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. [SOLVED] Macro to Copy data from Excel to Word and save each time as a different document
    By jorgeflores in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-13-2017, 08:12 AM
  2. Extract Word header table data to excel (closed word document)
    By Yakov on Excel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-14-2017, 02:12 PM
  3. [SOLVED] Save Word Document to New Location Using Excel VBA
    By TMcKay in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-03-2017, 05:37 PM
  4. open, edit, and save a word document based on user response in excel 2010 VBA
    By cmccabe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-19-2016, 03:13 PM
  5. Replies: 1
    Last Post: 01-18-2014, 09:32 PM
  6. Excel VBA Save a document created with word in both .doc and .html
    By Lavnpc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-18-2012, 01:01 PM
  7. Replies: 1
    Last Post: 05-14-2009, 11:01 AM

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