ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   xl to word procedure - troubles with references (xl2003) (https://www.excelbanter.com/excel-programming/425914-xl-word-procedure-troubles-references-xl2003.html)

Kragelund

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


OssieMac

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


Kragelund

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



All times are GMT +1. The time now is 08:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com