ByRef Type Mismatch error

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to get a procedure where a user browses for a file and check if it's open.

I've played around with this but it's giving me an error;

Code:
FileToOpen = Application.GetOpenFilename(FileFilter:="Excel Files (*.xlsm), *.xlsm")
If FileToOpen = "False" Then
ActiveWorkbook.Close SaveChanges:=False
End If
FilePath = Left$(FileToOpen, InStrRev(FileToOpen, "\"))
FileName = Mid$(FileToOpen, InStrRev(FileToOpen, "\") + 1)
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim xRet As Boolean
xRet = IsWorkBookOpen(FileToOpen)
If xRet Then
MsgBox "The file is open", vbInformation, "Excel"
Else
MsgBox "The file is not open", vbInformation, "Excel"
End If

I'm getting 'ByRef argument type mismatch' and it highlights 'FileToOpen' on the following line;

Code:
xRet = IsWorkBookOpen(FileToOpen)

Anyone know why this is happening?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
That would depend on the declaration of the IsWorkBookOpen function. What does that look like?

WBD
 
Upvote 0
Hi - here you go;

Code:
Function IsWorkBookOpen(Name As String) As Boolean
Dim xWb As Workbook
On Error Resume Next
Set xWb = Application.Workbooks.Item(Name)
IsWorkBookOpen = (Not xWb Is Nothing)
End Function
 
Upvote 0
Is FileToToOpen declared as a String?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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