LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.word.vba.general,microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Pasting Tables from Excel to Word

Hi,

I have to paste lot of tabulated data from excel to word. I have programmed
in Excel and pasted the code below.

Basically I look for the Word "Table " in Excel and copy the range till the
next instance of the word "Table "

Then I go to Winword and paste it. After pasting the present table I have to
do following 2 additional things in Word:-
A) I have to go to the end of the document - The excel code --
SDocument.Range.EndOf Unit:=wdStory, Extend:=wdExtend -- doesnt make the
cursor go to the end of the word document (Neither do I get any error). What
would be the correct code to make cursor go to end of Word document?

B) I have to then insert a Page Break after the present table- The Excel
code -- SDocument.Range.InsertBreak Type:=wdSectionBreakNextPage --
strangely clears the freshly pasted data. I have also tried the code
SDocument.Range.InsertBreak Type:=wdSectionBreakNextPage but this created a
page break ABOVE the freshly pasted data. How to create a page break after
the presently pasted data?

After doing the above the control goes back to excel and the process keeps
on repeating till there are no more words.

I have one more issue which is after pasting the Column Widths of table in
Word are thoroughly different as compared to what I have in Excel. The whole
table shoots off the right side of word margin. I have close to 26 columns
in excel and before pasting I reduce the widths and then copy but even then
in word it gets expanded. What is the syntax for controlling the column
width of a freshly pasted table?

Thanks a lot,
Hari
India

Option Explicit
Dim TableCount As Integer
Public SWinword As Word.Application
Public SDocument As Word.Document

Sub ExcelRangeProcess()

Dim TableStartRow As Long
Dim TableEndRow As Long
Dim EndColumnLetter As String
Dim MaxNumberofTable As Integer
Dim LastRow As Long
Dim CheckFortable As Boolean

LastRow = Range("A65536").End(xlUp).Row

'In my case EndColumnLetter is Z.
EndColumnLetter = InputBox("Enter the last Column LETTER in your PRESENT
Banner", "Banner Column")


In my case number of tables would be around 150.
MaxNumberofTable = InputBox("Enter the Number of Tables in your PRESENT
Banner")

Range("A1" & ":" & EndColumnLetter & LastRow).Select

Selection.Find(what:="TABLE ", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

TableStartRow = ActiveCell.Row + 10

For TableCount = 1 To MaxNumberofTable

Range("A" & TableStartRow & ":" & EndColumnLetter & LastRow).Select

Selection.Find(what:="TABLE ", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Activate

If Left(ActiveCell.Value, 6) = "TABLE " Then
CheckFortable = True
Else
CheckFortable = False
End If


While CheckFortable < True

Range("A" & ActiveCell.Row + 1 & ":" & EndColumnLetter & LastRow).Select

Selection.Find(what:="TABLE ", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=True, SearchFormat:=False).Activate

If Left(ActiveCell.Value, 6) = "TABLE " Then CheckFortable = True

Wend


TableEndRow = ActiveCell.Row - 6

Range("A" & TableStartRow & ":" & EndColumnLetter & TableEndRow).Select
Selection.Copy
Call TransferToWord

TableStartRow = TableEndRow + 16

Next TableCount

End Sub

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''Calling
WORD
application''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''

Sub TransferToWord()

If TableCount = 1 Then

Set SWinword = CreateObject("Word.application")
SWinword.Visible = msoTrue
Set SDocument = SWinword.Documents.Add

Else

Set SWinword = GetObject(, "Word.application")

End If


SDocument.Range.PasteAndFormat (wdPasteDefault)

SDocument.Range.EndOf Unit:=wdStory, Extend:=wdExtend

SDocument.Range.InsertBreak Type:=wdSectionBreakNextPage

End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pasting Tables together in Excel - Contents get Cut off Annabelle4876 Excel Discussion (Misc queries) 0 May 21st 08 06:28 PM
Pasting excel into word kmbenn0 Excel Discussion (Misc queries) 1 June 27th 07 09:50 PM
Pasting from Word into Excel Mel Excel Discussion (Misc queries) 1 January 12th 07 06:58 PM
Pasting a Word Table into Excel Dee Excel Discussion (Misc queries) 1 April 6th 05 01:38 AM
Pasting Excel To Word and resizing MTBer Excel Programming 2 May 16th 04 12:55 PM


All times are GMT +1. The time now is 02:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"