Convert Text to Table in Word from Excel (VBA)

japers

New Member
Joined
Dec 8, 2010
Messages
18
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:

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
Any help as usual, very gratefully received!
 
I would still like to know what the goal is for the last question you had to see if I can help quickly and give you some code to work with.

I am pleased to been able to help so far.
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,223,671
Messages
6,173,737
Members
452,533
Latest member
Alex19k

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top