We help IT Professionals succeed at work.
Get Started

Error 4605 when pasting from Excel into Word object

mesclun
mesclun asked
on
826 Views
Last Modified: 2007-12-19
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.application")
'Set wdDoc = wdObj.Documents.Add("normal.dot")
Set wdDoc = wdObj.Documents.Add("")
'wdObj.Visible = True
wdDoc.PageSetup.TopMargin = 65
wdDoc.PageSetup.LeftMargin = 95
wdDoc.PageSetup.RightMargin = 95
wdDoc.PageSetup.PageWidth = 612
wdDoc.PageSetup.PageHeight = 792

wdObj.Selection.PasteSpecial DataType:=wdPasteEnhancedMetafile

Range("B53:AD79").Select
Selection.Copy

wdObj.Selection.InsertBreak Type:=wdPageBreak
wdObj.Selection.GoTo What:=wdGoToPage, Which:=wdGoToLast
wdObj.Selection.PasteSpecial DataType:=wdPasteEnhancedMetafile

*****etc. until done*****
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE