mesclun
asked on
Error 4605 when pasting from Excel into Word object
Hi, I have some code in my Excel 2002 file that does this:
1. creates a word object
2. copies a range in Excel
3. sets the Word pagesetup parameters
4. pastes the range as an enhanced metafile into the word object
5. closes the word object.
someone wrote in complaining of a runtime 4605 error that i believe exists for Word 2000 users (I'm on Word 2002). according to this http://www.kbalertz.com/Feedback_275966.aspx I seem to be creating a frame.
below is my code. do you have any idea how to avoid or undo this whole Frame thing??
many many thanks
mesclun
*****code******
Sub ExportToWord()
Dim BuildFile As String
Dim wdObj As Object
Dim wdDoc As Object
Dim strFile As String
Const wdPasteEnhancedMetafile = 9
Const wdPageBreak = 7
Const wdGoToPage = 1
Const wdGoToFirst = 1
Const wdGoToLast = -1
Application.ScreenUpdating = False
BuildFile = MsgBox("This will save a Word document to your C:\ drive.", vbOKOnly, "Build")
If BuildFile = vbOK Then
Range("B1:AD52").Select
Selection.Copy
Set wdObj = CreateObject("word.applica tion")
'Set wdDoc = wdObj.Documents.Add("norma l.dot")
Set wdDoc = wdObj.Documents.Add("")
'wdObj.Visible = True
wdDoc.PageSetup.TopMargin = 65
wdDoc.PageSetup.LeftMargin = 95
wdDoc.PageSetup.RightMargi n = 95
wdDoc.PageSetup.PageWidth = 612
wdDoc.PageSetup.PageHeight = 792
wdObj.Selection.PasteSpeci al DataType:=wdPasteEnhancedM etafile
Range("B53:AD79").Select
Selection.Copy
wdObj.Selection.InsertBrea k Type:=wdPageBreak
wdObj.Selection.GoTo What:=wdGoToPage, Which:=wdGoToLast
wdObj.Selection.PasteSpeci al DataType:=wdPasteEnhancedM etafile
*****etc. until done*****
1. creates a word object
2. copies a range in Excel
3. sets the Word pagesetup parameters
4. pastes the range as an enhanced metafile into the word object
5. closes the word object.
someone wrote in complaining of a runtime 4605 error that i believe exists for Word 2000 users (I'm on Word 2002). according to this http://www.kbalertz.com/Feedback_275966.aspx I seem to be creating a frame.
below is my code. do you have any idea how to avoid or undo this whole Frame thing??
many many thanks
mesclun
*****code******
Sub ExportToWord()
Dim BuildFile As String
Dim wdObj As Object
Dim wdDoc As Object
Dim strFile As String
Const wdPasteEnhancedMetafile = 9
Const wdPageBreak = 7
Const wdGoToPage = 1
Const wdGoToFirst = 1
Const wdGoToLast = -1
Application.ScreenUpdating
BuildFile = MsgBox("This will save a Word document to your C:\ drive.", vbOKOnly, "Build")
If BuildFile = vbOK Then
Range("B1:AD52").Select
Selection.Copy
Set wdObj = CreateObject("word.applica
'Set wdDoc = wdObj.Documents.Add("norma
Set wdDoc = wdObj.Documents.Add("")
'wdObj.Visible = True
wdDoc.PageSetup.TopMargin = 65
wdDoc.PageSetup.LeftMargin
wdDoc.PageSetup.RightMargi
wdDoc.PageSetup.PageWidth = 612
wdDoc.PageSetup.PageHeight
wdObj.Selection.PasteSpeci
Range("B53:AD79").Select
Selection.Copy
wdObj.Selection.InsertBrea
wdObj.Selection.GoTo What:=wdGoToPage, Which:=wdGoToLast
wdObj.Selection.PasteSpeci
*****etc. until done*****
ASKER
Awesome--I will go test this.
Thanks Rajesh.
Thanks Rajesh.
ASKER
Hey, I received a 4120 Bad Parameter when I tried that.
After poking around I tried adding the line
wdObj.Selection.TypeParagr aph
so:
***********
wdDoc.PageSetup.PageHeight = 792
wdObj.Selection.PasteSpeci al DataType:=wdPasteEnhancedM etafile
Range("B53:AD79").Select
Selection.Copy
wdObj.Selection.TypeParagr aph ' <----- Added this line
wdObj.Selection.InsertBrea k Type:=wdPageBreak
wdObj.Selection.GoTo What:=wdGoToPage, Which:=wdGoToLast
wdObj.Selection.PasteSpeci al DataType:=wdPasteEnhancedM etafile
***********
This appeared to take care of the problem.
Mesclun
After poking around I tried adding the line
wdObj.Selection.TypeParagr
so:
***********
wdDoc.PageSetup.PageHeight
wdObj.Selection.PasteSpeci
Range("B53:AD79").Select
Selection.Copy
wdObj.Selection.TypeParagr
wdObj.Selection.InsertBrea
wdObj.Selection.GoTo What:=wdGoToPage, Which:=wdGoToLast
wdObj.Selection.PasteSpeci
***********
This appeared to take care of the problem.
Mesclun
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The workaround of course is to unselect the picture before inserting the pagebreak
.
.
.
Range("B53:AD79").Select
Selection.Copy
wdObj.Selection.EndKey Unit:=wdStory '<---------------- add this line
wdObj.Selection.InsertBrea
.
.
.
Rajesh