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.
Bookmarks