Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default xl to word procedure - troubles with references (xl2003)

Hi,

this (part of a ) procedure has worked for several months, now its suddenly
failing, when implemented in a new worksheet. Apparently the procedure now
doen't recognise the reference to a bookmark in Word.

The procedure now stops at "wdGoToBookmark", where I get the error message
"compile error - can't find project or library".

The difference between the functioning version and the version that doesn't
perform is that the former references to a word 11 library, while the latter
refers to a Word 12 library. In the non-performing version, I can't selecxt
the word 11 library. I think this may be where the problem is. Is there a way
out?

The code:

Sub Xl_to_Word()
Dim h, i, j, k As Integer
Dim name As Variant
'Dim wdGoToBookmark, wdPasteText, wdInLine As Variant
Dim WordRep As Object

Set WordRep = CreateObject("Word.Application")

Application.ScreenUpdating = False
Application.CutCopyMode = False

WordRep.Documents.Open "G:\plan.doc"

WordRep.Visible = True

For k = 1 To 6 'Insert acronyms in the document
worksheets("Statusark").Range("c66").Copy
WordRep.Selection.GoTo what:=wdGoToBookmark, name:="PR1_rep" & k
WordRep.Selection.PasteSpecial Link:=False, DataType:=wdPasteText,
Placement:=wdInLine, DisplayAsIcon:=False

worksheets("Statusark").Range("E66").Copy
WordRep.Selection.GoTo what:=wdGoToBookmark, name:="PR2_rep" & k
WordRep.Selection.PasteSpecial Link:=False, DataType:=wdPasteText,
Placement:=wdInLine, DisplayAsIcon:=False
Next k
..
..
..
End sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default xl to word procedure - troubles with references (xl2003)

Hi,

Question. Are your Excel and Word both version 2007? or are you using Excel
2007 and word 2003 is still the word application on the computer?

I have copied your code to an Excel 2007 workbook. The only change I made is
to the path and I changed the loop to For k = 1 To 1 so it only does one pass.

I created plan.doc in Word 2002 and inserted bookmarks PR1_rep1 and PR2_rep1.

I then copied the file to the computer with xl2007 (still as a doc file in
xl2002 format).

Your code works fine. Word 2007 opens the word doc in compatibility mode and
your Excel code copies the data from C66 and E66.

Check that your bookmark names have not been corrupted. Delete and re-insert
the first one to test.

When you added the Reference Microsoft Word 12.0 Object Library, you did
check the box and not just highlight the line and click OK? (I am not trying
to be funny here; I have seen it occur.)

--
Regards,

OssieMac


"Kragelund" wrote:

Hi,

this (part of a ) procedure has worked for several months, now its suddenly
failing, when implemented in a new worksheet. Apparently the procedure now
doen't recognise the reference to a bookmark in Word.

The procedure now stops at "wdGoToBookmark", where I get the error message
"compile error - can't find project or library".

The difference between the functioning version and the version that doesn't
perform is that the former references to a word 11 library, while the latter
refers to a Word 12 library. In the non-performing version, I can't selecxt
the word 11 library. I think this may be where the problem is. Is there a way
out?

The code:

Sub Xl_to_Word()
Dim h, i, j, k As Integer
Dim name As Variant
'Dim wdGoToBookmark, wdPasteText, wdInLine As Variant
Dim WordRep As Object

Set WordRep = CreateObject("Word.Application")

Application.ScreenUpdating = False
Application.CutCopyMode = False

WordRep.Documents.Open "G:\plan.doc"

WordRep.Visible = True

For k = 1 To 6 'Insert acronyms in the document
worksheets("Statusark").Range("c66").Copy
WordRep.Selection.GoTo what:=wdGoToBookmark, name:="PR1_rep" & k
WordRep.Selection.PasteSpecial Link:=False, DataType:=wdPasteText,
Placement:=wdInLine, DisplayAsIcon:=False

worksheets("Statusark").Range("E66").Copy
WordRep.Selection.GoTo what:=wdGoToBookmark, name:="PR2_rep" & k
WordRep.Selection.PasteSpecial Link:=False, DataType:=wdPasteText,
Placement:=wdInLine, DisplayAsIcon:=False
Next k
.
.
.
End sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default xl to word procedure - troubles with references (xl2003)

Hi OssieMac,

Thanks for your reply. No, in fact my Excel is 2003 (office 11), my Word
version is 2007 (office 12), but I created the code in Word 11, so there may
be an issue here. Can it really be true, that I can't run the procedure with
a newer version of Word? Anyways, the answer must be in those parts.

Thanks!


"OssieMac" wrote:

Hi,

Question. Are your Excel and Word both version 2007? or are you using Excel
2007 and word 2003 is still the word application on the computer?

I have copied your code to an Excel 2007 workbook. The only change I made is
to the path and I changed the loop to For k = 1 To 1 so it only does one pass.

I created plan.doc in Word 2002 and inserted bookmarks PR1_rep1 and PR2_rep1.

I then copied the file to the computer with xl2007 (still as a doc file in
xl2002 format).

Your code works fine. Word 2007 opens the word doc in compatibility mode and
your Excel code copies the data from C66 and E66.

Check that your bookmark names have not been corrupted. Delete and re-insert
the first one to test.

When you added the Reference Microsoft Word 12.0 Object Library, you did
check the box and not just highlight the line and click OK? (I am not trying
to be funny here; I have seen it occur.)

--
Regards,

OssieMac


"Kragelund" wrote:

Hi,

this (part of a ) procedure has worked for several months, now its suddenly
failing, when implemented in a new worksheet. Apparently the procedure now
doen't recognise the reference to a bookmark in Word.

The procedure now stops at "wdGoToBookmark", where I get the error message
"compile error - can't find project or library".

The difference between the functioning version and the version that doesn't
perform is that the former references to a word 11 library, while the latter
refers to a Word 12 library. In the non-performing version, I can't selecxt
the word 11 library. I think this may be where the problem is. Is there a way
out?

The code:

Sub Xl_to_Word()
Dim h, i, j, k As Integer
Dim name As Variant
'Dim wdGoToBookmark, wdPasteText, wdInLine As Variant
Dim WordRep As Object

Set WordRep = CreateObject("Word.Application")

Application.ScreenUpdating = False
Application.CutCopyMode = False

WordRep.Documents.Open "G:\plan.doc"

WordRep.Visible = True

For k = 1 To 6 'Insert acronyms in the document
worksheets("Statusark").Range("c66").Copy
WordRep.Selection.GoTo what:=wdGoToBookmark, name:="PR1_rep" & k
WordRep.Selection.PasteSpecial Link:=False, DataType:=wdPasteText,
Placement:=wdInLine, DisplayAsIcon:=False

worksheets("Statusark").Range("E66").Copy
WordRep.Selection.GoTo what:=wdGoToBookmark, name:="PR2_rep" & k
WordRep.Selection.PasteSpecial Link:=False, DataType:=wdPasteText,
Placement:=wdInLine, DisplayAsIcon:=False
Next k
.
.
.
End sub

Reply
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
formula references two embedded excel objects in Word doc Jeff Excel Worksheet Functions 1 August 15th 08 02:08 AM
Obtaining Active Document Name from WORD for Excel procedure Tim Childs Excel Programming 4 April 11th 06 09:11 AM
Dynamic References to Word? Newbie Excel Programming 15 April 9th 06 10:28 AM
Unable to run Excel addin procedure from Word Amir Excel Programming 6 August 6th 05 12:48 AM
Missing Word 10 Object Error References Rajan Excel Programming 1 July 23rd 03 02:12 PM


All times are GMT +1. The time now is 10:47 AM.

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

About Us

"It's about Microsoft Excel"