PDA

View Full Version : Word Macro not run in Mac



Rakesh
09-16-2014, 04:20 PM
Hi,


I am using Mac OS X, Version 10.6.8, Office for Mac 2011

The below macro Works in Windows PC and not work in Mac and shows the following error in the below 2 lines

Compile error:
wrong number of arguments or Invalid property assignment


InString = replace(InString, Delims(Ndx) & Delims(Ndx), Delims(Ndx))

InString = replace(InString, Delims(Ndx), Chr(1))

Is there any command equal to the replace command


Function SplitEx(ByVal InString As String, IgnoreDoubleDelmiters As Boolean, _
ParamArray Delims() As Variant) As String()
Dim Arr() As String
Dim Ndx As Long
Dim N As Long

If Len(InString) = 0 Then
SplitEx = Arr
Exit Function
End If
If IgnoreDoubleDelmiters = True Then
For Ndx = LBound(Delims) To UBound(Delims)
N = InStr(1, InString, Delims(Ndx) & Delims(Ndx), vbTextCompare)
Do Until N = 0

InString = replace(InString, Delims(Ndx) & Delims(Ndx), Delims(Ndx))
N = InStr(1, InString, Delims(Ndx) & Delims(Ndx), vbTextCompare)
Loop
Next Ndx
End If


ReDim Arr(1 To Len(InString))
For Ndx = LBound(Delims) To UBound(Delims)
InString = replace(InString, Delims(Ndx), Chr(1))
Next Ndx
Arr = split(InString, Chr(1))
SplitEx = Arr
End Function

'This allows mutiple delimiters of different lenghts. For example, to split on |, :: and ,, you would call the function like

Sub AAA()
Dim S As String
Dim T() As String
Dim N As Long
S = "this||is some::delimited,text"
T = SplitEx(S, True, "||", "::", ",")
For N = LBound(T) To UBound(T)
Debug.Print N, T(N)
Next N
End Sub

Thanks,
Rakeshh

jbs
12-15-2014, 01:12 PM
Hi Rakesh,
I had the same issue with the function Mid in Office for Mac 2011, and I solved it by prepending "VBA." to the function.

So in your code you can try this:



InString = VBA.replace(InString, Delims(Ndx) & Delims(Ndx), Delims(Ndx))

InString = VBA.replace(InString, Delims(Ndx), Chr(1))

Maybe you also need to add the "VBA." prefix to other members or constants defined in the VBA library, like 'vbTextCompare'.

Hope it works for your issue.
Cheers