Sep 24 2021 12:18 PM - edited Sep 25 2021 02:58 AM
I have created below code to copy data and paste into word the code is working fine but the problem is when it paste the data into word document then i convert the table into text.
Then there are 2 to 3 tables in the Excel data (which i want to keep as it is in word document) which also removes in the word document.
Excel tables
Sub ExcelWordPaste()
Dim objWord As Object
Dim objDoc As Object
Application.ScreenUpdating = False
Application.EnableEvents = False
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Range("B3:AP198").Copy
Set objDoc = objWord.Documents.Add
With objDoc.Range
.PasteExcelTable False, False, False
.Tables(1).AutoFitBehavior 2
.InsertAfter vbCr
End With
objWord.Selection.Rows.ConvertToText Separator:=wdSeparateByTabs, NestedTables:= _
True
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Sep 24 2021 01:57 PM - edited Sep 24 2021 01:57 PM
Interesting .
Sub ExportToWord()
Dim WordApp As Word.Application, WordDocument As Word.Document
Set WordApp = New Word.Application
WordApp.Visible = True
Set WordDocument = WordApp.Documents.Add
ActiveSheet.UsedRange.Copy
WordDocument.Range.Paste
Application.CutCopyMode = False
Dim tbl As Object
For Each tbl In WordDocument.Tables
tbl.AutoFitBehavior wdAutoFitContent
Next
WordDocument.SaveAs Filename:=Application.ActiveWorkbook.Path & "\" & ActiveSheet.Name
Set WordDocument = Nothing
Set WordApp = Nothing
End Sub
If it helps you, remember to flag it as solved and hit the like button.
Sep 25 2021 02:00 AM
Sep 25 2021 02:45 AM
Sep 25 2021 03:00 AM - edited Sep 25 2021 03:01 AM
Yes it works as mine but when i convert the Word Table to Text it removes the Excel Original tables. These are https://ibb.co/G36M177 I do not wat to remove excel original tables in wod after Converting text to table
Sep 25 2021 03:15 AM - edited Sep 25 2021 03:17 AM
Sep 25 2021 04:22 AM