Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default "ByRef argument type mismatch" error

I get the above stated compile error when I run the following code:

Dim myfile as String
myfile = "Book1.xlsm"

If Module1.IsWbOpen (myfile) Then
' Do stuff
End If

------------------[ IsWbOpen() is in Module1]--------------------

Public Function IsWbOpen(WbName As String) As Boolean
For Each wb In Application.Workbooks
If wb.Name = WbName Then
IsWbOpen = True
Exit For
End If
Next
End Function
--------------------------------------------------------------------


Does anybody know what the heck is wrong here??? I know i am
definitely passing a String variable into "IsWbOpen()", yet I am
seeing a compile error.

Thank you!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default "ByRef argument type mismatch" error

Hi Robert,

I can't fault the code. It works perfectly. What line does the code stop on
when you get the error? You did copy your code from your project and not
re-write it for this post didn't you?

The error msge suggests that myfile is incorrectly declared as something
other than a string.

--
Regards,

OssieMac


"Robert Crandal" wrote:

I get the above stated compile error when I run the following code:

Dim myfile as String
myfile = "Book1.xlsm"

If Module1.IsWbOpen (myfile) Then
' Do stuff
End If

------------------[ IsWbOpen() is in Module1]--------------------

Public Function IsWbOpen(WbName As String) As Boolean
For Each wb In Application.Workbooks
If wb.Name = WbName Then
IsWbOpen = True
Exit For
End If
Next
End Function
--------------------------------------------------------------------


Does anybody know what the heck is wrong here??? I know i am
definitely passing a String variable into "IsWbOpen()", yet I am
seeing a compile error.

Thank you!


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "ByRef argument type mismatch" error


The fix is to add ByVal to the subroutinge declaration. The code
works without the change on My PC with 2003. You omust have a different
option checked in your PC or using a different version of Excel thenI'm
using.

From:

Public Function IsWbOpen(WbName As String) As Boolean

To

Public Function IsWbOpen(Byval WbName As String) As Boolean



The default declaration of a function is ByRef which means if the
variable is changed in the Calling subroutine the change will be seen by
the called function. like this

Sub Main()
Dim MyName As String
MyName = "Joel"
Call ChangeName(MyName)
MsgBox (MyName) 'this will pring Robert
End Sub

Sub ChangeName(Person As String)
Person = "Robert"
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=165247

Microsoft Office Help

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"ByRef argument type mismtach" on string variable *sometimes* [email protected] Excel Programming 10 June 4th 09 07:41 PM
"Compile Error: ByRef argument type mismatch" when calling my function from another module ker_01 Excel Programming 2 August 14th 08 03:53 PM
HELP "ByRef Argument Type Mismatch" RocketMan[_2_] Excel Programming 6 June 7th 07 07:00 PM
"ByRef argument type mismatch" Error Baapi[_4_] Excel Programming 2 September 17th 05 12:47 AM
ByRef argument type mismatch error? sermest Excel Programming 4 June 17th 05 06:50 PM


All times are GMT +1. The time now is 10:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"