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
'****************************
'* 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
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,
Just traded in my OLD subtlety...
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
RE: Syntax problem in AttachMate macro working with MS Word
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
But your 4 Bookmarks ought to have 4 separate names or just 1 to 4...
CODE
Skip,
for a NUance!
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
RE: Syntax problem in AttachMate macro working with MS Word
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.