Results 1 to 1 of 1

Advanced export from Excel to Word - Tables (with formating), Text and Chart

Threaded View

  1. #1
    Registered User
    Join Date
    06-16-2017
    Location
    Wroclaw
    MS-Off Ver
    2016
    Posts
    1

    Question Advanced export from Excel to Word - Tables (with formating), Text and Chart

    Hello everyone,
    At first I have to say that I am new at VBA but I try really hard to understand and solve it.

    I have prepared the macro which export some data (tables) from excel to word. I am using tables with names.
    But, I also would like to make a automatically caption of table and text (from excel cell), autofit table to word window, change style of text and change table style.
    I using a word template, so all styles are set up.
    How to do the same with chart ?
    How to add texts in Headings ?

    Code that I use:

    Sub ExportToWord()
    
    Dim wdApp As Word.Application, wdDoc As Word.Document, ws As Worksheet, path As String
    
    Application.ScreenUpdating = False
    Application.StatusBar = "Creating new document..."
    Set wdApp = New Word.Application
    path = ThisWorkbook.path & "\"
    
    
    Set wdDoc = wdApp.Documents.Add(path & "mytemplate.docx")
    
    For Each ws In ActiveWorkbook.Worksheets
        ws.Range("Table.1").Copy
        wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.InsertParagraphAfter
        wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.Paste
        Application.CutCopyMode = False
        wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.InsertParagraphAfter
        ws.Range("Table.2").Copy
        wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.InsertParagraphAfter
        wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.Paste
        Application.CutCopyMode = False
        
        If Not ws.Name = Worksheets(Worksheets.Count).Name Then
            With wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range
                .InsertParagraphBefore
                .Collapse Direction:=wdCollapseEnd
                .InsertBreak Type:=wdPageBreak
            End With
        End If
    
    Next ws
    
    Set ws = Nothing
    
    Application.StatusBar = "Cleaning up..."
    
    Set wdDoc = Nothing
    wdApp.Visible = True
    Set wdApp = Nothing
    Application.StatusBar = False
    
    End Sub
    Thank you for your help and reply.
    Last edited by Dziabo; 06-17-2017 at 03:10 AM.

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 Export Word Tables to Excel
    By WesternGal in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-16-2018, 05:08 AM
  2. Macro to export MS Word tables to Excel
    By drakosss in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-19-2015, 08:43 AM
  3. Replies: 0
    Last Post: 01-25-2013, 07:03 AM
  4. Is there any way to export your Chart from Excel to Word
    By Skyler in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-28-2006, 09:40 AM
  5. [SOLVED] How to export text from Excel to Word
    By Rock in forum Excel General
    Replies: 2
    Last Post: 05-13-2006, 07:45 PM
  6. How to export text from Excel to Word
    By Rock in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 05-13-2006, 07:45 PM
  7. [SOLVED] Help with date formating when export to Word
    By a0relento in forum Excel General
    Replies: 3
    Last Post: 10-15-2005, 09:05 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