PC Review


Reply
Thread Tools Rate Thread

"ByRef argument type mismtach" on string variable *sometimes*

 
 
paul.domaskis@gmail.com
Guest
Posts: n/a
 
      3rd Jun 2009
I am using the code at http://www.vbaexpress.com/kb/archive.php/k-743.html
to change the color of some text in an Excel 2003 spreadsheet. I am
using the following type of invocation:

Dim TargetString, OtherString As String
TargetString = "QuickBrownFox"
Call xlCellTextMgmt( SomeCell, _
TargetString , , , , , ColorIndexRed )

This generates the error in the subject line. However, this
invocation is fine:

Call xlCellTextMgmt( SomeCell, _
"QuickBrownFox", , , , , ColorIndexRed )

This invocation is fine, too:

OtherString = "QuickBrownFox"
SomeCell = OtherString
Call xlCellTextMgmt( SomeCell, _
OtherString, , , , , ColorIndexRed )

What could possibly cause the first invocation to give the subject
error?
 
Reply With Quote
 
 
 
 
paul.domaskis@gmail.com
Guest
Posts: n/a
 
      3rd Jun 2009
Here is the test code with the troublesome code highlighted. The
Excel file must have a spreadsheet with tab name "Test".

Option Explicit

Public Sub Aggregate()

Dim TargetString, OtherString As String
Dim SomeCell As Range
Dim ColorIndexRed As Integer

ColorIndexRed = 3
Set SomeCell = Sheets("Test").Range("A1")
TargetString = "QuickBrownFox"

' Troublesome code
'-------------------
'Call xlCellTextMgmt(SomeCell, _
' TargetString, , , , , ColorIndexRed)

Call xlCellTextMgmt(SomeCell, _
"QuickBrownFox", , , , , ColorIndexRed)

OtherString = "QuickBrownFox"
SomeCell = OtherString

Call xlCellTextMgmt(SomeCell, _
OtherString, , , , , ColorIndexRed)

End Sub

---------- Forwarded message ----------
From: paul.domas...@gmail.com
Date: Jun 3, 3:13*pm
Subject: "ByRef argument type mismtach" on string variable *sometimes*
To: microsoft.public.excel.programming


I am using the code athttp://www.vbaexpress.com/kb/archive.php/k-743.html
to change the color of some text in an Excel 2003 spreadsheet. *I am
using the following type of invocation:

Dim TargetString, OtherString As String
TargetString = "QuickBrownFox"
Call xlCellTextMgmt( SomeCell, _
* *TargetString , , , , , ColorIndexRed )

This generates the error in the subject line. *However, this
invocation is fine:

Call xlCellTextMgmt( SomeCell, _
* *"QuickBrownFox", , , , , ColorIndexRed )

This invocation is fine, too:

OtherString = "QuickBrownFox"
SomeCell = OtherString
Call xlCellTextMgmt( SomeCell, _
* *OtherString, , , , , ColorIndexRed )

What could possibly cause the first invocation to give the subject
error?
 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      3rd Jun 2009
TargetString is a Variant and the called function is expecting a String...

Dim TargetString as String
Dim OtherString as String
--
Jim Cone
Portland, Oregon USA

 
Reply With Quote
 
paul.domaskis@gmail.com
Guest
Posts: n/a
 
      4th Jun 2009
On Jun 3, 3:34*pm, "Jim Cone" <james.cone...@comcast.netxxx> wrote:
> TargetString is a Variant and the called function is expecting a String....
>
> Dim TargetString as String
> Dim OtherString as String


Thanks, Jim. I need to read the Help more carefully (though
admittedly, this behaviour does depart from many other languages).
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
"ByRef argument type mismatch" error Robert Crandal Microsoft Excel Programming 1 27th Dec 2009 11:21 AM
"Type mismtach error" using DoCmd.TransferSpreadsheet Harry-Wishes Microsoft Access VBA Modules 2 20th Jun 2009 08:08 AM
"Compile Error: ByRef argument type mismatch" when calling my function from another module ker_01 Microsoft Excel Programming 2 14th Aug 2008 03:53 PM
HELP "ByRef Argument Type Mismatch" RocketMan Microsoft Excel Programming 6 7th Jun 2007 07:00 PM
ByRef argument type mismatch Scott Microsoft Access Form Coding 1 15th Jun 2006 07:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:45 PM.