Excel sheet to word document

P

papou

Hi all
Office 2K
I am trying to copy an excel sheet into word using VBA.
For better page settings purposes, the Excel sheet is pasted as an RTF
document into an existing word document :
Sheets("Saisie").Range(LaPlgCopie).Copy
WdApp.Selection.PasteSpecial Link:=False, DataType:=wdPasteRTF
and this works OK.
But I cannot figure out how to tell Word that the first line of the pasted
sheet is the heading (titles) since I have several pages.
I have been trying with the Word macro recorder but this won't work.
I also need to do some operations on this particular line.
I would be grateful if somebody could help.
TIA
Regards
Pascal
 
P

papou

Ok it seems it would be possible using a bookmark
Unfortunately the code at line 8 below does not work in my Excel Module and
returns an error # 438 (I have been using it in Word and it works)
Here's part of my Excel module:
Public Sub CopToWd()
On Error GoTo HandleErr
Application.ScreenUpdating = False
Set WdApp = GetObject(, "Word.Application")
Set WdAppDoc = WdApp.ActiveDocument
WdApp.Selection.InsertBreak Type:=wdSectionBreakNextPage
Bkmk = WdAppDoc.Bookmarks.Add("DebutTable",
WdAppDoc.Selection)

Could somebody help please
TIA
Regards
Pascal
 
D

Doug Robbins - Word MVP

Hi Pascal,

Try

Application.ScreenUpdating = False
Set WdApp = GetObject(, "Word.Application")
Set WdAppDoc = WdApp.ActiveDocument
WdApp.Selection.InsertBreak Type:=wdSectionBreakNextPage
Bkmk = WdAppDoc.Bookmarks.Add("DebutTable", Selection.Range)

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
P

papou

Hello Doug
Thank you for your answer.
Unfortunately this does not work either I keep getting an error #450.
It seems that the expression Selection.Range makes Excel "confused"
Any other ideas welcome! I keep trying on my own anyway.
Thanks Doug
Regards
Pascal
 
D

Doug Robbins - Word MVP

Hi Pascal,

Where is Name:= being used?

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
P

papou

Hi Doug
I eventually made it work
Here's the change :
Public Sub CopToWd()
On Error GoTo HandleErr
Application.ScreenUpdating = False
Dim WdApp As Object
Dim WdAppDoc
Dim WdAppBkmk
Set WdApp = GetObject(, "Word.Application")
Set WdAppDoc = WdApp.ActiveDocument
Set WdAppBkmk = WdAppDoc.Bookmarks
'saut de page nouvelle section
WdApp.Selection.InsertBreak Type:=wdSectionBreakNextPage
'ajout signet début de tableau
WdAppBkmk.Add "DebutTable"

Now I have come across another problem so I will post another message.

Thanks for your help
Regards
Pascal
 

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