Using methods in functions with arguments.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
Maybe it's plain simple but to me it looks strange:
The following code:
Sub OpenIt()
Dim fileSaveName
fileSaveName = Application.GetSaveAsFilename("NBN.txt", "Text Files
..txt), *.txt", , "Save NBN B62-003 as text file")
End Sub
Opens the SaveAs dialog box.
But with the code
Function OpenIt(Teta As Double) As Double
Dim fileSaveName
fileSaveName = Application.GetSaveAsFilename("NBN.txt", "Text Files
(*.txt), *.txt", , "Save NBN B62-003 as text file")
End Function
the dialog box is not openend.

How come? Does excel prohibit dialog boxes in functions?
The function is used as a worksheet function.
THank you veru much
Bart
 
Are you trying to use the function in a worksheet?

in the immediate window:
? Openit(21#)

displayed the dialog. What's the problem. There is no restriction unless
you are trying to call it from a worksheet cell (which, on the surface,
doesn't make much sense anyway).
 
BartDesc said:
Hello,
Maybe it's plain simple but to me it looks strange:
The following code:
Sub OpenIt()
Dim fileSaveName
fileSaveName = Application.GetSaveAsFilename("NBN.txt", "Text Files
.txt), *.txt", , "Save NBN B62-003 as text file")
End Sub
Opens the SaveAs dialog box.
But with the code
Function OpenIt(Teta As Double) As Double
Dim fileSaveName
fileSaveName = Application.GetSaveAsFilename("NBN.txt", "Text Files
(*.txt), *.txt", , "Save NBN B62-003 as text file")
End Function
the dialog box is not openend.

How come? Does excel prohibit dialog boxes in functions?
The function is used as a worksheet function.
THank you veru much
Bart

You can't have a cell function that opens a file dialog. I think it will
work if you call your modified function with a parameter from Sub OpenIt().
Not from a cell, though.

/Fredrik
 
Back
Top