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

Syntax problem 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 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
 
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,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
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?
 
You might want to post your MS Word question in Forum707.

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,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top