HELP WITH WORK/EXCEL MACRO

  • Thread starter Daniel R. Young
  • Start date
D

Daniel R. Young

I have a macro where I paste cells into a word document, but it does not
center on the page. I want the table to center with a macro. Can someone
help?

Here is my code:
Private Sub CommandButton1_Click()
Worksheets("Report").Unprotect
Dim rng As Range, c As Range
Set rng = Selection
For Each c In rng
If c.Interior.ColorIndex = 15 Then
c.Interior.ColorIndex = 2
End If
Next c
For Each c In rng
If c.Font.ColorIndex = 5 Then
c.Font.ColorIndex = 2
End If
Next c

Range("A1:J9769").Select
Selection.Copy
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String

myDocName = "Survey Report.doc"

'Open Word and add a new document
Set WDApp = CreateObject("Word.Application")
WDApp.Visible = True
WDApp.Activate
Set WDDoc = WDApp.Documents.Add

WDDoc.Range.Paste
WDDoc.Selection.tables(1).Rows.Alignment = .wdAlignRowCenter
Worksheets("Report").Protect
ws_exit:
Application.EnableEvents = True
End Sub

Thank you!!!!
Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top