My second question of the day! I am succesfully copying text from a Excel into a new document in Word using VBA but I am struggling to then convert the resulting table into text (this text is formatted so I cannot choose Paste Special --> unformatted text).
My code is below, the first part is copied and adapted from various code I found on this forum. The second part if a combination of Macro recorder and more internet searches. My problem, I think, is that I don't know how to refer to the appropriate command:
Any help as usual, very gratefully received!
My code is below, the first part is copied and adapted from various code I found on this forum. The second part if a combination of Macro recorder and more internet searches. My problem, I think, is that I don't know how to refer to the appropriate command:
Code:
Sub CopyWorksheetToWord()
' requires a reference to the Word Object library:
' in the VBE select Tools, References and check the Microsoft Word X.X object library
Worksheets("Award").Range("C1:E50").Copy
Dim ws As Worksheet
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Application.ScreenUpdating = False
Application.StatusBar = "Creating new document..."
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Add
wdDoc.Range.Paste
Application.CutCopyMode = False
' apply print view
With wdApp.ActiveWindow
If .View.SplitSpecial = wdPaneNone Then
.ActivePane.View.Type = wdPrintView
Else
.View.Type = wdPrintView
End If
End With
' Second Part Below - First Part Above Works
wdApp.Visible = True
wdApp.Activate
With ActiveDocument. ' Here is my problem!!! Tried many combinations.
.Rows.ConvertToText Separator:=wdSeparateByTabs, NestedTables:= _
True
End With
' Parts Below untested as Table needs to be converted first
wdDoc.Select
With ActiveDocument.PageSetup
.RightMargin = CentimetersToPoints(4)
End With
With ActiveDocument.Styles(wdStyleNormal).Font
.name = "Arial"
.Size = 12
End With
End Sub