×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!
  • Students Click Here

*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.

Students Click Here

Jobs

Syntax problem using Selection.GoTo method in AttachMate macro working with MS Word

Syntax problem using Selection.GoTo method in AttachMate macro working with MS Word

Syntax problem using Selection.GoTo method in AttachMate macro working with MS Word

(OP)
I’m not very fluent in VB macro language but somebody has to do it. My problem is with a syntax error that I don’t see the reason. This is an Attachmate macro to work with MS Word document. I will have a template document fully edited and formatted with bookmarks for screen shots. Macro will open this document, issue Attachmate command to grab a screen and use Word Selection.GoTo method to position at proper bookmark and paste screen shot there. Problem is that when I use required four GoTo parameters this statement is flagged as syntax error. When I coded just one parameter it was compiled fine but I need four. Other Word methods, EndOf, TypeText, Paste compile fine and work fine. What am I doing wrong?
'****************************
'* Paste screen into Word
'****************************
sub pasteScreenDoc (byRef tsoSession as object, byRefr objDoc as object, strDesc as String, strScreen as String)
Dim wdWhat As Integer ' GoToBookmark = -1
Dim wdWhich As Integer ' GoToFirst = 1
Dim wdCnt As Integer ' Count = 1
Dim objSelection As object
'****************************
'* Print Screen and paste to Word
'****************************
SendKeys "%{PRTSCR}", True
Set objSelection = objDoc.application.Selection
'
wdWhat% = -1
wdWhich% = 1
wdCount% = 1
objSelection.GoTo(wdWhat,wdWhich,wdCnt,strScreen) '<= marked as syntax
' objSelection.GoTo(strScreen) <= this is ok
objSelection.TypeText(strDesc)
objSelection.Paste
end sub

RE: Syntax problem using Selection.GoTo method in AttachMate macro working with MS Word

>objSelection.GoTo(wdWhat,wdWhich,wdCnt,strScreen)

If you were developing this in Word's VBA IDE then you'd be seeing a Compile error for this line the moment you type it in, optimistically (but erroneously) suggesting you need an "=". Basically, you are using the wrong calling convention for an object method with multiple parameters

Try one of the following instead:

Call objSelection.GoTo(wdWhat,wdWhich,wdCnt,strScreen)

or

objSelection.GoTo wdWhat,wdWhich,wdCnt,strScreen

RE: Syntax problem using Selection.GoTo method in AttachMate macro working with MS Word

(OP)
Thank you. Both ways work fine with a little exception: Word returns message "This bookmark does not exist". When I open this document in Word the bookmark is there and its name is the same as I use it in this call. To be sure I displayed bookmark name right before invoking GoTo. I also TypeText it into document and can see that Word get this bookmark name correctly. What else can I do have Word go to my bookmark?

RE: Syntax problem using Selection.GoTo method in AttachMate macro working with MS Word

(OP)
Found solution:
call objSelection.GoTo(wdWhat,,,strScreen)

RE: Syntax problem using Selection.GoTo method in AttachMate macro working with MS Word

See the Word wdGoToItem and wdGoToDirection enumeration constants you can put in your code and what you put as default.

combo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!

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