Mike.and.H
Programmer
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