VBA - Calling a function to return boolean to check if file exists -
I am writing to write a VBA program whether a function is present through the function that returns the boolean However, I have a problem with the "file = filesexists (strandtfile name, strodet path)" line, VBA states that due to the mismatch of the problem type I really do not know how to fix it. Please help people
ps sorry code maybe a bit messy as I am doing an amateur in VBA programming
function fileexists (ByVal sPathName string, as the alternative directory boolean form In), start the error on Boolean as next, then sPathName & lt; & Gt; "" Then the fileexists = (Dir $ (sPathName, vbDirectory) <> "> then" IsMissing (Directory) or Directory = false then fileexists = (Dir $ (sPathName) <"> ) Finally if end end function sub ah () const strDataPath string = as "c: \ users \" retard string strFileName string as strdatafileName as string dim file boolean dim wbNew as workbook strDataFileName = "past Data "file = fileexists (strDataFileName boolean dim ExistWS, strDataPath) if file = false then set wbNew = Workbooks.Add Sheets.Add D: = ActiveSheet SHEETNAME = Format (date, "dd-mm-yyyy") ActiveSheet.Name = SHEETNAME wbNew.SaveAs file name: = (strDataPath & strDataFileName), file format: = 52 wbNew.Close Else cells ( 2,3) = one true ???? Ending the end sub
Your second parameter is designated a boolean if it is a directory is required.
This replacement should work on that line:
file = fileexists (strDataPath & strDataFileName, incorrect)
Comments
Post a Comment