+ Reply to Thread
Results 1 to 3 of 3

Don't understand why I'm getting an argument not optional

  1. #1
    Brett Smith
    Guest

    Don't understand why I'm getting an argument not optional

    I am using this program to replace text in other excel vba files. I don't
    understand why it is highlighting the ReplacecodeInModule and saying ,
    "Compile Error: Argument not optional". It worked before, but what happend
    now? I have the code below.

    Sub FileSearchforMacros2()

    Dim i As Integer
    Dim wkbkOne As Workbook

    With Application.FileSearch
    .LookIn = "C:\Documents and
    Settings\BSmith\Desktop\workfiles\changecode"
    .SearchSubFolders = True
    .FileType = msoFileTypeExcelWorkbooks
    If .Execute() > 0 Then
    'MsgBox "There were " & .FoundFiles.Count & _
    ' "file(s) found."
    For i = 1 To .FoundFiles.Count
    ' MsgBox .FoundFiles(i)
    Set wkbkOne = Application.Workbooks.Open( _
    .FoundFiles(i), , , , Password:=("INGRAM"))
    ReplacecodeInModule wkbkOne
    ReplacecodeInModule2 wkbkOne
    remove_xlfit3_ref wkbkOne
    wkbkOne.Save
    wkbkOne.Close
    Next i
    Else
    MsgBox "There were no files found."
    End If
    End With
    End Sub

    ----------------------------------------------------------------------------------------------

    Sub ReplacecodeInModule(RepWk As Workbook, myFStr As Variant, myRStr As
    Variant)
    Dim myCode As String
    'Dim myFStr As Variant
    'Dim myRStr As Variant
    Dim myMod As VBComponent

    myFStr = Array("XLfit3_", "ExcludePoints", "IncludePoints")
    myRStr = Array("xf4_", "ExcludePoint", "IncludePoint")

    For Each myMod In RepWk.VBProject.VBComponents
    With myMod.CodeModule

    If .CountOfLines > 0 Then
    myCode = .Lines(1, .CountOfLines)
    If InStr(1, myCode, myFStr(i)) > 0 Then
    'MsgBox myCode
    myCode = Replace(myCode, myFStr(i), myRStr(i))
    'MsgBox myCode

    .DeleteLines 1, .CountOfLines
    .InsertLines .CountOfLines + 1, myCode
    End If
    End If
    End With
    Next myMod
    End Sub

    --------------------------------------------------------------------------------------------
    Sub ReplacecodeInModule2(RepWk2 As Workbook, myFStr2 As Variant, myRStr2 As
    Variant)

    Dim myCode2 As String
    Dim myMod2 As VBComponent

    myFStr2 = Array("XLFitExcludePoint", "XLFitIncludePoint", "YRange")
    myRStr2 = Array("xf4_ExcludePoint", "xf4_IncludePoint", "RangeY")

    For Each myMod2 In RepWk2.VBProject.VBComponents
    With myMod2.CodeModule

    If .CountOfLines > 0 Then
    myCode2 = .Lines(1, .CountOfLines)
    If InStr(1, myCode2, myFStr(i)) > 0 Then
    myCode2 = Replace(myCode2, myFStr2(i), myRStr2(i))

    .DeleteLines 1, .CountOfLines
    .InsertLines .CountOfLines + 1, myCode2
    End If
    End If
    End With
    Next myMod2
    End Sub

  2. #2
    Bob Phillips
    Guest

    Re: Don't understand why I'm getting an argument not optional

    Untested, but try this
    ]
    Sub FileSearchforMacros2()

    Dim i As Integer
    Dim wkbkOne As Workbook

    With Application.FileSearch
    .LookIn = "C:\Documents and
    Settings\BSmith\Desktop\workfiles\changecode"
    .SearchSubFolders = True
    .FileType = msoFileTypeExcelWorkbooks
    If .Execute() > 0 Then
    'MsgBox "There were " & .FoundFiles.Count & _
    ' "file(s) found."
    For i = 1 To .FoundFiles.Count
    ' MsgBox .FoundFiles(i)
    Set wkbkOne = Application.Workbooks.Open( _
    .FoundFiles(i), , , , Password:=("INGRAM"))
    ReplacecodeInModule wkbkOne
    ReplacecodeInModule2 wkbkOne
    remove_xlfit3_ref wkbkOne
    wkbkOne.Save
    wkbkOne.Close
    Next i
    Else
    MsgBox "There were no files found."
    End If
    End With
    End Sub

    ----------------------------------------------------------------------------
    ------------------

    Sub ReplacecodeInModule(RepWk As Workbook)
    Dim myCode As String
    Dim myFStr As Variant
    Dim myRStr As Variant
    Dim myMod As VBComponent

    myFStr = Array("XLfit3_", "ExcludePoints", "IncludePoints")
    myRStr = Array("xf4_", "ExcludePoint", "IncludePoint")

    For Each myMod In RepWk.VBProject.VBComponents
    With myMod.CodeModule

    If .CountOfLines > 0 Then
    myCode = .Lines(1, .CountOfLines)
    If InStr(1, myCode, myFStr(i)) > 0 Then
    'MsgBox myCode
    myCode = Replace(myCode, myFStr(i), myRStr(i))
    'MsgBox myCode

    .DeleteLines 1, .CountOfLines
    .InsertLines .CountOfLines + 1, myCode
    End If
    End If
    End With
    Next myMod
    End Sub

    ----------------------------------------------------------------------------
    ----------------
    Sub ReplacecodeInModule2(RepWk2 As Workbook)

    Dim myCode2 As String
    Dim myFStr As Variant
    Dim myRStr As Variant
    Dim myMod2 As VBComponent

    myFStr2 = Array("XLFitExcludePoint", "XLFitIncludePoint", "YRange")
    myRStr2 = Array("xf4_ExcludePoint", "xf4_IncludePoint", "RangeY")

    For Each myMod2 In RepWk2.VBProject.VBComponents
    With myMod2.CodeModule

    If .CountOfLines > 0 Then
    myCode2 = .Lines(1, .CountOfLines)
    If InStr(1, myCode2, myFStr(i)) > 0 Then
    myCode2 = Replace(myCode2, myFStr2(i), myRStr2(i))

    .DeleteLines 1, .CountOfLines
    .InsertLines .CountOfLines + 1, myCode2
    End If
    End If
    End With
    Next myMod2
    End Sub

    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "Brett Smith" <[email protected]> wrote in message
    news:[email protected]...
    > I am using this program to replace text in other excel vba files. I don't
    > understand why it is highlighting the ReplacecodeInModule and saying ,
    > "Compile Error: Argument not optional". It worked before, but what

    happend
    > now? I have the code below.
    >




  3. #3
    Gary''s Student
    Guest

    RE: Don't understand why I'm getting an argument not optional

    Re-examine:

    ReplacecodeInModule wkbkOne
    ReplacecodeInModule2 wkbkOne
    --
    Gary's Student


    "Brett Smith" wrote:

    > I am using this program to replace text in other excel vba files. I don't
    > understand why it is highlighting the ReplacecodeInModule and saying ,
    > "Compile Error: Argument not optional". It worked before, but what happend
    > now? I have the code below.
    >
    > Sub FileSearchforMacros2()
    >
    > Dim i As Integer
    > Dim wkbkOne As Workbook
    >
    > With Application.FileSearch
    > .LookIn = "C:\Documents and
    > Settings\BSmith\Desktop\workfiles\changecode"
    > .SearchSubFolders = True
    > .FileType = msoFileTypeExcelWorkbooks
    > If .Execute() > 0 Then
    > 'MsgBox "There were " & .FoundFiles.Count & _
    > ' "file(s) found."
    > For i = 1 To .FoundFiles.Count
    > ' MsgBox .FoundFiles(i)
    > Set wkbkOne = Application.Workbooks.Open( _
    > .FoundFiles(i), , , , Password:=("INGRAM"))
    > ReplacecodeInModule wkbkOne
    > ReplacecodeInModule2 wkbkOne
    > remove_xlfit3_ref wkbkOne
    > wkbkOne.Save
    > wkbkOne.Close
    > Next i
    > Else
    > MsgBox "There were no files found."
    > End If
    > End With
    > End Sub
    >
    > ----------------------------------------------------------------------------------------------
    >
    > Sub ReplacecodeInModule(RepWk As Workbook, myFStr As Variant, myRStr As
    > Variant)
    > Dim myCode As String
    > 'Dim myFStr As Variant
    > 'Dim myRStr As Variant
    > Dim myMod As VBComponent
    >
    > myFStr = Array("XLfit3_", "ExcludePoints", "IncludePoints")
    > myRStr = Array("xf4_", "ExcludePoint", "IncludePoint")
    >
    > For Each myMod In RepWk.VBProject.VBComponents
    > With myMod.CodeModule
    >
    > If .CountOfLines > 0 Then
    > myCode = .Lines(1, .CountOfLines)
    > If InStr(1, myCode, myFStr(i)) > 0 Then
    > 'MsgBox myCode
    > myCode = Replace(myCode, myFStr(i), myRStr(i))
    > 'MsgBox myCode
    >
    > .DeleteLines 1, .CountOfLines
    > .InsertLines .CountOfLines + 1, myCode
    > End If
    > End If
    > End With
    > Next myMod
    > End Sub
    >
    > --------------------------------------------------------------------------------------------
    > Sub ReplacecodeInModule2(RepWk2 As Workbook, myFStr2 As Variant, myRStr2 As
    > Variant)
    >
    > Dim myCode2 As String
    > Dim myMod2 As VBComponent
    >
    > myFStr2 = Array("XLFitExcludePoint", "XLFitIncludePoint", "YRange")
    > myRStr2 = Array("xf4_ExcludePoint", "xf4_IncludePoint", "RangeY")
    >
    > For Each myMod2 In RepWk2.VBProject.VBComponents
    > With myMod2.CodeModule
    >
    > If .CountOfLines > 0 Then
    > myCode2 = .Lines(1, .CountOfLines)
    > If InStr(1, myCode2, myFStr(i)) > 0 Then
    > myCode2 = Replace(myCode2, myFStr2(i), myRStr2(i))
    >
    > .DeleteLines 1, .CountOfLines
    > .InsertLines .CountOfLines + 1, myCode2
    > End If
    > End If
    > End With
    > Next myMod2
    > End Sub


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1