Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having troubles across Excel and Word

Status
Not open for further replies.

davefish

Technical User
Jul 26, 2002
169
GB
I'm Having troubles across Excel and Word and wonder if anyone can help. I have a table in Excel populated with data and I wish to pass a specific cell value to a bookmark in word. I have sucessfully transfered a paragraph, but cannot get a single cell value to appear to it's bookmark. Here's my code
Public Sub Wap()

Const wdWindowStateMaximize As Integer = 1
Const wdNormalView As Integer = 3
Const wdAlignParagraphCenter As Integer = 1
Const wdPageFitFullPage As Integer = 1
Const wdGoToLine As Integer = 3

Dim WordDoc As Object
Set WordApp = CreateObject("Word.Application")
With WordApp
.Visible = True
.WindowState = wdWindowStateMaximize
WordApp.Documents.Open Filename:="C:\....Path....\test template.dot", _
ReadOnly:=False
Set WordDoc = .ActiveDocument
End With
WordDoc.ActiveWindow.View = wdNormalView
Selection.Goto What:=wdwdGoToBookmark, Name:="NAME"
Selection.InsertAfter Sheet1.Range("H10")


End Sub

I get an error message stating the bookmark cannot be found against the GotO statement, yet I know it's there in the Word template. Any ideas anyone??
 
Hi!
1) Don't call your bookmark "Name" - it's a reserved word and can cause probs. Call it Firstname or Surname or whatever...
2) There's one wd too many....
-->Selection.Goto What:=wdGoToBookmark, [blue]Name:="e.g. SurName"[/blue]

OK?
[pipe]
MakeItSo


Andreas Galambos
EDP / Technical Support Specialist
Bowne Global Solutions Wuppertal, Germany
(andreas.galambos@bowneglobal.de)
HP:
 
Hi Andreas,

Thanks for spotting the typo! The extra wd was a copy and paste issue. I can get this code to work from Word OK, but if I try and initial this from a standard Excel module it still gives ma an error message "Object doesn't support this property or method". Any Ideas?

Dave
 
AAAAh - me dummy! should have seen this:
It's the Selection:
Excel thinks that its Selection is meant, so you gotta tell it you want Word's Selection:
WordApp.Selection... should do it...
:-D

Andreas Galambos
EDP / Technical Support Specialist
Bowne Global Solutions Wuppertal, Germany
(andreas.galambos@bowneglobal.de)
HP:
 
Hi Andreas,

I tried your solution and got an error message stating error 5101 'This bookmark does not exist'. I checked and it sure does! The bookmark lies within the word document template and can be accessed manually after Excel has launched Word. I can't understand why it's not working can you?
here's the modified code

Dave


WordDoc.ActiveWindow.View = wdNormalView
WordApp.Selection.Goto What:=wdGoToBookmark, Name:="FirstName"
Selection.InsertAfter Sheet1.Range("H10")
 
Andreas,

I don't know if this helps but if I exchange my Goto line to another pointing to an absolute line number it works! I tried following the syntax for the GoToBookmark, but again it failed. Does this help?

Dave

PS: I comma'd out the line as shown below for the bookmark


WordDoc.ActiveWindow.View = wdNormalView
WordApp.Selection.Goto What:=wdGoToLine, Which:=wdGoToAbsolute, Count:=10

''WordApp.Selection.Goto What:=wdGoToItem, Which:=wdGoToBookmark, Name:="Rate"
WordApp.Selection.InsertAfter Sheet1.Range("J13")
 
Guess I have! And you skipped another "Selection": ;-)
Replace
WordApp.Selection.Goto What:=wdGoToBookmark, Name:="FirstName"
Selection.InsertAfter Sheet1.Range("H10")

with
WordDoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="FirstName"
WordDoc.ActiveWindow.Selection.InsertAfter Sheet1.Range("H10")


Hope this works. Good luck,
Andy
 
Hi,

I'm attempting the same thing, and the code as modified works great, except (there's always something!) - it adds the data from the cell, but not after the bookmark. Is there something missing regarding InsertAfter?

Thanks!
Sheri
 
Hi Sheri,

I've modified my approach somewhat to pull the data from memory, but I tried the code below and it works to your requirements. It places the data after a bookmark called "QNAME" with no problem, whether it's from memory or a cell location. Other than that I cannot offer any further advice as I cannot see your code. If you'd send a sample I'll try and fettle itm for you.

WordDoc.ActiveWindow.View = wdNormalView
WordDoc.ActiveWindow.Selection.Goto What:=wdGoToBookmark, Name:="QNAME"
WordDoc.ActiveWindow.Selection.InsertAfter Sheet6.Range("E4")


Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top