Hello all ,
I don't have much experience in Excel although quite a bit in programming.
I have written a custom function,
the data to be used are in a different woorkbook so I tried to open it within the function with no luck.
The same part of the code run as a sub works perfectly.
I have attached the code below could you please help me,
many many thanks,


Function OutPutGet1(Date1 As Date, Machine1 As String) As Variant

Dim i, j
Dim MyWbook As String
Dim Date2 As Date
Dim Machine2 As String

If Date1 = 0 Or Machine1 = "" Then
OutPutGet1 = "Not available!"
GoTo Skip
End If

Select Case Machine1

Case "Tomo 1"

If Date1 <= 39218 Then
MyWbook = "H\:namefile.xls"

Workbooks.Open (MyWbook)
With Workbooks(MyWbook).Worksheets("Daily Dosechecker").Cells(5, 7)
j = .Value
MsgBox j
End With
OutPutGet1 = j
Else
OutPutGet1 = "Not calculated!"
End If

Case "Tomo 2"
OutPutGet1 = "Hello"
End Select
End Function


Sub MyOpen()
Dim namefile As String
Dim j
namefile = "H:namefile.xls"
Workbooks.Open (MyWbook)
With Workbooks(namefile).Worksheets("Daily Dosechecker").Cells(5, 7)
j = .Value
MsgBox j
End With
End Sub