Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I can't sort this error out

Status
Not open for further replies.

richiwatts

Technical User
Jun 21, 2002
180
GB
I have created a global template containing various macros. I created it in VB6 but also wanted it to work on VB5. Because I needed to use the "split" function I needed a way to make it work.

I found this page
Simulate Visual Basic 6.0 String Functions in VB5

I used the code for the split function and when I tested the template in Word 97, I got the following error message:

Compile error:
Automation type not supported in Visual Basic

It highlighted the following part of the code.

Code:
Public Function Split(ByVal sIn As String, Optional sDelim As _
       String, Optional nLimit As Long = -1, Optional bCompare As _
       VbCompareMethod = vbBinaryCompare) As Variant

Has anyone got any ideas?
 
Split is a reserved word in VBA referring to a split screen, try using a different name.
 
Nope that didn't work

I tried both "Word97" and "Different" as name and got the same error message

Richi
 
Can you send the full code for the function as I've tried it with out anything in it and am getting no error messages.
Plus, I'd rather like a split function in VBA so sorting this would be good.
 
My template requires that yuo have a text file in the same location as the template copy these couple of line in a .txt file and store it in the same folder as the template, remember I am only getting this error when I try to run on word 97:

aisles isles
allied elide
allowed aloud
allude elude
allusion illusion

Code:
Sub ScanDocument()
   Dim oRg As Range
   Dim LineFromFile As String, LineString As String
   Dim path As String
   Dim WordArray As Variant
   Dim indx As Integer, LparenPos As Integer, RparenPos As Integer
   Dim WholeDocument As String
   
   Options.DefaultHighlightColorIndex = wdTurquoise
   If CheckExpiration = False Then Exit Sub

   WholeDocument = LCase$(ActiveDocument.Range.Text)

   path = ThisDocument.path
  Open path & Application.PathSeparator & "data.txt" For Input As #1
   Do While Not EOF(1)
        Line Input #1, LineString
        LparenPos = InStr(LineString, "(")
        Do While LparenPos > 0
            RparenPos = InStr(LparenPos, LineString, ")")
            If RparenPos > 0 Then
                LineString = Left(LineString, LparenPos - 2) & _
                    Right(LineString, Len(LineString) - RparenPos)
                LparenPos = InStr(LineString, "(")
            End If
        Loop
        LineFromFile = LineFromFile & vbTab & LineString
   Loop
   Close #1

   #If VB6 Then
   WordArray = Split(LineFromFile, vbTab)
   #Else
   WordArray = Word97Split(LineFromFile, vbTab)
   #End If

   Set oRg = ActiveDocument.Range

   Application.ScreenUpdating = False

   With oRg.Find
      .ClearFormatting
      .Replacement.ClearFormatting

      .Replacement.Highlight = True

      .Replacement.Text = &quot;^&&quot; ' <= code for &quot;found text&quot;
      .Forward = True
      .Wrap = wdFindContinue
      .Format = True
      .MatchCase = False
      .MatchWholeWord = True
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False

      For indx = 1 To UBound(WordArray)
         If InStr(WholeDocument, LCase$(WordArray(indx))) > 0 Then
            .Text = WordArray(indx)
            .Execute Replace:=wdReplaceAll
         End If
         StatusBar = UBound(WordArray) - indx
         DoEvents
      Next indx
   End With

   Application.ScreenUpdating = True
End Sub

Public Function Word97Split(ByVal sIn As String, Optional sDelim As _
      String, Optional nLimit As Long = -1, Optional bCompare As _
       VbCompareMethod = vbBinaryCompare) As Variant
    Dim sRead As String, sOut() As String, nC As Integer
    If sDelim = &quot;&quot; Then
        Word97Split = sIn
    End If
    sRead = ReadUntil(sIn, sDelim, bCompare)
    Do
        ReDim Preserve sOut(nC)
        sOut(nC) = sRead
        nC = nC + 1
        If nLimit <> -1 And nC >= nLimit Then Exit Do
        sRead = ReadUntil(sIn, sDelim)
    Loop While sRead <> &quot;&quot;
    ReDim Preserve sOut(nC)
    sOut(nC) = sIn
    Word97Split = sOut
End Function

Public Function ReadUntil(ByRef sIn As String, _
      sDelim As String, Optional bCompare As VbCompareMethod _
    = vbBinaryCompare) As String
    Dim nPos As String
    nPos = InStr(1, sIn, sDelim, bCompare)
    If nPos > 0 Then
        ReadUntil = Left(sIn, nPos - 1)
        sIn = Mid(sIn, nPos + Len(sDelim))
    End If
End Function
 
Unfortunately, I don't have Word at home but it worked fine in Excel.
I would suggest checking the references in Word VB and ensure they're the same as you have in Excel. I'm going to try it at work on Mon & see if that's the prob.

Let me know if it is, save me the effort.

While I'm on, I'm gonna post a request to help me get Word working.
 
Richi,

For whatever reason, Word97 doesn't like that the enumerated type vbCompareMethod is referenced in the function declaration, although it accepts the vbBinaryCompare constant. Change vbCompareMethod to Long or Integer and it should work fine. I've tested this in Word97 and it works for me.


Regards,
Mike
 
I just removed vbCompareMethod as I didn't need it anyway.

It works now, Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top