Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

davefish (TechnicalUser) (OP)
25 Nov 03 7:46
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??
MakeItSo (Programmer)
25 Nov 03 8:29
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, Name:="e.g. SurName"

OK?

MakeItSo

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

davefish (TechnicalUser) (OP)
25 Nov 03 8:46
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
MakeItSo (Programmer)
25 Nov 03 8:53
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...

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

davefish (TechnicalUser) (OP)
25 Nov 03 9:15
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")
davefish (TechnicalUser) (OP)
25 Nov 03 10:08
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")
MakeItSo (Programmer)
25 Nov 03 10:10
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
DancingGeek (Programmer)
15 Dec 03 12:52
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
davefish (TechnicalUser) (OP)
16 Dec 03 4:13
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

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close