Microsoft Word - Save As Object

Gary96

Member
Hi,

I am getting a compile error when trying to include a timeout as part of the Save as action for Microsoft word on Blue Prism.

Code Stage:

ExecWithTimeout(Timeout, "Save As",
Sub()
Dim doc as Object = GetDocument(handle,documentname)
doc.SaveAs(filename)
newname = doc.name
End Sub)


Error:

Page: Save As
Stage: SaveAs
Type: Error
Action: Validate
Description: Compiler error at line 1: 'ExecWithTimeout' is not declared. It may be inaccessible due to its protection level.
Repairable: No
 

sahil_raina_91

Active Member
Hi,

I am getting a compile error when trying to include a timeout as part of the Save as action for Microsoft word on Blue Prism.

Code Stage:

ExecWithTimeout(Timeout, "Save As",
Sub()
Dim doc as Object = GetDocument(handle,documentname)
doc.SaveAs(filename)
newname = doc.name
End Sub)


Error:

Page: Save As
Stage: SaveAs
Type: Error
Action: Validate
Description: Compiler error at line 1: 'ExecWithTimeout' is not declared. It may be inaccessible due to its protection level.
Repairable: No
There are a couple of issues with what you are trying to achieve:
1) The ExecWithTimeout is a private Function/Sub which is a part of Excel VBO and not Word VBO, which is why you are getting the error
2) newname = doc.name will generate an error in a lambda expression, as newname is the output data item
3) You will have to return the doc.name instead and for that will have to use Function() instead of Sub(), since Sub() can't return a value


In the global code of Word VBO, copy below Sub and Function:

Private Sub ExecWithTimeout(timeout As Integer, name As String, operation As Action)
Dim ar = operation.BeginInvoke(Nothing, Nothing)
If Not ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(timeout)) Then
Throw New TimeoutException(name & " took more than " & timeout & " secs.")
End If
operation.EndInvoke(ar)
End Sub

Private Function ExecWithTimeout(Of T)(timeout As Integer, name As String, operation As Func(Of T)) As T
Dim ar = operation.BeginInvoke(Nothing, Nothing)
If Not ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(timeout)) Then
Throw New TimeoutException(name & " took more than " & timeout & " secs.")
End If
return operation.EndInvoke(ar)
End Function


In the local code of Save As:

newname = ExecWithTimeout(Timeout, "Save As",
Function()
Dim doc as Object = GetDocument(handle,documentname)
doc.SaveAs(filename)
Return doc.name
End Function)


The above changes should fix the issues
 
Top