Hi,
a problem is driving me bonkers and I'd love to have help with it!
Task for vba: copy data into a new word document, partially as pictures, partially as tables, so users can edit it.
There is probably a much better way to write the code, so it is stable and doesn't stop once in a while. Is there a parameter for the pasteSpecial method that makes text not hidden?
Thanks for reading and helping
a problem is driving me bonkers and I'd love to have help with it!
Task for vba: copy data into a new word document, partially as pictures, partially as tables, so users can edit it.
Code:
Sub ExcelToWord()
Dim wdApp As Object
Dim wdDoc As Object
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Add
wdApp.Visible = True
ThisWorkbook.Sheets("Part 1").Range("A1:S39").Copy
wdApp.Selection.PasteSpecial Link:=False, DataType:=9, _
Placement:=wdInLine, DisplayAsIcon:=False
wdApp.Selection.Characters.Last.Select
ThisWorkbook.Sheets("Part 2").Range("A1:D43").Copy
wdApp.Selection.PasteSpecial Link:=False, DataType:=10, _
Placement:=wdInLine, DisplayAsIcon:=False
wdApp.Selection.Characters.Last.Select
ThisWorkbook.Sheets("Part 3").Range("A26:T45").Copy
wdApp.Selection.PasteSpecial Link:=False, DataType:=9, _
Placement:=wdInLine, DisplayAsIcon:=False
'I added this part below, because text copied from excel appeared as hidden in the word document
'This is also the part where the macro stops sometimes
wdApp.Selection.Wholestory
wdApp.Selection.Font.Hidden = False
wdApp.Selection.Characters.First.Select
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
There is probably a much better way to write the code, so it is stable and doesn't stop once in a while. Is there a parameter for the pasteSpecial method that makes text not hidden?
Thanks for reading and helping