Compile error: ByRef argument type mismatch in VBA

thommo41

Board Regular
Joined
Nov 10, 2006
Messages
142
Hi, I'm stuck trying to diagnose the below code, the error "Compile error: ByRef argument type mismatch in VBA" occurs at the line If FileOrDirExists(htmpath) = True Then fso.DeleteFile (htmpath)

Can anyone help? Many thanks...

Function FileOrDirExists(PathName As String) As Boolean
Dim iTemp As Integer
On Error Resume Next
iTemp = GetAttr(PathName)

Select Case Err.Number
Case Is = 0
FileOrDirExists = True
Case Else
FileOrDirExists = False
End Select

On Error GoTo 0
End Function

Sub expgraphs()
Dim fso
Dim exppath, filname, htmpath, folderpath As String
exppath = "C:\Documents and Settings\art\Desktop\MA BINC\graphs\"
filname = Left(ThisWorkbook.Name, (Len(ThisWorkbook.Name)) - 4)
htmpath = exppath & filname & ".htm"
htmpath = htmpath
MsgBox (htmpath)
Set fso = CreateObject("Scripting.FileSystemObject")
If FileOrDirExists(htmpath) = True Then fso.DeleteFile (htmpath)
End Sub

Regards, Alan
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Alan

There's only 1 variable in that code declared as String - folderpath.

You can't declare multiple variables as a particular type like that in VBA, though I know you can in other languages.
Code:
Dim exppath As String
Dim filname As String
Dim htmpath As String
Dim folderpath As String
 
Upvote 0
Oh, bugger :) I can't believe I've only come a cropper today - I've been doing that for years haha. Thank You!
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top