View Full Version : [SOLVED:] Calling a function
DeanP
06-14-2019, 09:02 AM
I am trying to call a function from a sub routine but cannot do it. Error: argument not optional. I've researched in a lot of places to find a solution but I don't really understand the answers people give.
The function I'm using checks whether a file already exists:
Function FileExist(FilePath As String) As Boolean
I want to call this function from another macro. Using "Call FileExist" doesn't work, what will?
JKwan
06-14-2019, 09:29 AM
Try:
dim ReturnCode
ReturnCode = FileExist("c:\test.txt")
msgbox ReturCode
Paul_Hossler
06-14-2019, 11:03 AM
I am trying to call a function from a sub routine but cannot do it. Error: argument not optional. I've researched in a lot of places to find a solution but I don't really understand the answers people give.
The function I'm using checks whether a file already exists:
Function FileExist(FilePath As String) As Boolean
I want to call this function from another macro. Using "Call FileExist" doesn't work, what will?
In the definition
Function FileExist(FilePath As String) As Boolean
FilePath is the 'Argument'. 'Not Optional' means that it is required
Since it is supposed to determine if a file exists, you have to tell it which file you want to check
If FileExists ("C:\Users\MyName\Documents\Report.xlsx") Then
' do if true
Else
' do if not there
End IF
J FelixBosco
06-14-2019, 11:27 PM
Dim doesFileExist as Boolean
doesFileExist=FileExist("C:\SomeFileName.txt")
DeanP
06-17-2019, 06:21 AM
Thank you all for your help!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.