×
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 in AttachMate macro working with MS Word

Syntax problem in AttachMate macro working with MS Word

Syntax problem in AttachMate macro working with MS Word

(OP)
I’m not very fluent in Attachment VB macro language but somebody has to do it. My problem is with a syntax error that I don’t see the reason. Original macro was grabbing multiple screens and pasted them to MS Word document with some text description. Then it required a lot of editing and formatting in Word. I had this idea that instead of appending new document at the end I will have template document fully edited and formatted with bookmarks for screen shots. Macro will open this document, issue an existing SendKeys to navigate to required screen, grab it, 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 (that I’m replacing with GoTo), TypeText, Paste compile fine and work fine. What am I doing wrong? How to get more details from the red bug?
'****************************
'* 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
'
' old code objSelection.EndOf
'
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

Second problem I have with Word is that I can only open a new document:

'****************************
'* prepare word document. parameter is document location.
'****************************
Function initWordApplication(strWordDoc As String) as Object
Dim objWord As Object
Dim objDoc As Object
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Document.Add
' Set objDoc = objWord.document.Open <== fails
objWord.Visible = True
objWird.WindowsState = 2
Set initWordApplication = objDoc
end Function

Commented out statement "Open" fails on execution. "Add" works. How to open an existing document in macro?
Thanks

RE: Syntax problem in AttachMate macro working with MS Word

Hi,

Having just read your post and searched for Open, I notice that there is no FileName argument, as is required to open an existing document.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: Syntax problem in AttachMate macro working with MS Word

(OP)
Yes, thank you. I found it yesterday. I have the document opened now. Still compiler allows only one argument with Word GoTo method. I tried to go around it with this:
Dim parmStr As String
...
parmStr = "-1,1,1," + strScreen
objSelection.GoTo(parmStr)
When run macro went into some infinite loop, not response at all and after killing whole Extra! task my Super Session lost my sessions customization. By the way how to break (cancel, stop, kill) runaway macro?

RE: Syntax problem in AttachMate macro working with MS Word

You might want to post your MS Word question in forum707: VBA Visual Basic for Applications (Microsoft).

But your 4 Bookmarks ought to have 4 separate names or just 1 to 4...

CODE

objWord.Bookmarks(sName).Range.Paste 
...where sName is one of your Bookmark names.

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: Syntax problem in AttachMate macro working with MS Word

(OP)
I'll move Word question to suggested forum.
If it were only 4 I wouldn't bother with macro. It is more then 100 screenshots and the same number of bookmarks, each with unique name for its screenshot. Your suggestion is perfect: table of names and loop the process for each. Thanks.

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! Already a Member? Login

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