Results 1 to 9 of 9

help with "invalid procedure call or argument" error.

Threaded View

  1. #1
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    help with "invalid procedure call or argument" error.

    I cannot figure out what is wrong with this code. I've run it on one workbook and it worked like it always does. Then I run it on the one I need and it fails after seven exports. I even moved the eight sheet to the front to see if that was causing it to fail. Nope. It has something to do with the filenames of about 13 of them. I can't provide those, they are personal info, but I am hoping someone might point me in the right direction for why I am getting "invalid procedure call or argument" error (see bolded part in code below). I can't do an On Error Resume Next, because it puts Exported next to the file that would have otherwise stopped to exports. It needs to say the Not exported, then I can troubleshoot.

    'Export Notepads as Pdfs and Save with correct Filenames
    
    Option Explicit
    
    Sub ED5ExportNotepadPDFFilename()
    Dim wsLIST As Worksheet, ws As Worksheet, fPATH As String, Errors As Boolean
    Dim fileLIST As Range, fNAME As Range, MyArr As Variant
    
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .InitialFileName = ActiveWorkbook.Path
        .Show
        If .SelectedItems.Count > 0 Then
            fPATH = .SelectedItems(1) & "\"
        Else
            MsgBox "No destination selected, aborting..."
            Exit Sub
        End If
    End With
    Set wsLIST = ActiveWorkbook.ActiveSheet
    Set fileLIST = wsLIST.Range("A:A").SpecialCells(xlConstants)
    fileLIST.Offset(, 1).ClearContents
    
    For Each fNAME In fileLIST
        MyArr = Split(fNAME.Value, ", ")
        For Each ws In ActiveWorkbook.Worksheets
            If InStr(ws.Range("A1"), MyArr(2)) > 0 Then
                If InStr(ws.Range("B1"), MyArr(0)) > 0 Then
                    If InStr(ws.Range("B1"), MyArr(1)) > 0 Then
                        ws.ExportAsFixedFormat _
                            Type:=xlTypePDF, _
                            FileName:=fPATH & fNAME.Value & ".pdf", _
                            Quality:=xlQualityStandard, _
                            IncludeDocProperties:=True, _
                            IgnorePrintAreas:=False, _
                            OpenAfterPublish:=False
                        fNAME.Offset(, 1).Value = "exported"
                        Exit For
                    End If
                End If
            End If
            If ws.Index = ActiveWorkbook.Sheets.Count Then
                fNAME.Offset(, 1).Value = "NOT FOUND"
                Errors = True
            End If
        Next ws
    Next fNAME
    
    
    
    Columns("B:B").EntireColumn.AutoFit
        Columns("B:B").Select
        ActiveWorkbook.Worksheets("Sheet31").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Sheet31").Sort.SortFields.Add Key:=Range("B1"), _
            SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Sheet31").Sort
            .SetRange Range("A2:B219")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    If Errors Then MsgBox "Not all filenames/sheets were matched. See FILENAMES column B"
    
    End Sub
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by taylorsm; 05-02-2017 at 11:33 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Invalid procedure call or argument error
    By maym in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-10-2016, 09:38 PM
  2. [SOLVED] run time error '5" invalid procedure call or argument
    By jay11 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-12-2015, 12:29 PM
  3. Run-time Error 5 "Invalid Procedure Call or Argument"
    By dinakar.yadav in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-15-2014, 09:22 AM
  4. Invalid procedure call or argument (Error 5)
    By vop2311 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-08-2014, 07:27 PM
  5. WritetoSheet causing "invalid procedure call or argument"
    By cmb80 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2013, 03:46 PM
  6. "Invalid procedure call or argument" error when creating Pivot table
    By Kaigi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2009, 06:02 AM
  7. [SOLVED] Invalid procedure call or argument error
    By Patrick Simonds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2006, 06:45 PM

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