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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

Mike.and.H

Programmer
May 13, 2019
7
US
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
 
>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:

[tt]Call objSelection.GoTo(wdWhat,wdWhich,wdCnt,strScreen)[/tt]

or

[tt]objSelection.GoTo wdWhat,wdWhich,wdCnt,strScreen[/tt]
 
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?
 
Found solution:
call objSelection.GoTo(wdWhat,,,strScreen)
 
See the Word wdGoToItem and wdGoToDirection enumeration constants you can put in your code and what you put as default.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top