+ Reply to Thread
Results 1 to 9 of 9

run time error '5" invalid procedure call or argument

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    run time error '5" invalid procedure call or argument

    hi can u guys help me i try to print PDF from wb in the folder my code giving this error thaks in advance .
    Option Explicit
    Sub aaa()
         
        Dim xRow As Long
        Dim Path, Fname, InitialFoldr$
         Dim nName As String, ndir, strPDFName, fileSaveName
         Dim wkb As Workbook
         Dim ws As Worksheet
                               Dim dlater As String, getwbn
    
         
        InitialFoldr$ = "D:\" '
         
        With Application.FileDialog(msoFileDialogFolderPicker)
            .InitialFileName = Application.DefaultFilePath & "\"
            .Title = "Please select a folder to list Files from"
            .InitialFileName = InitialFoldr$
            .Show
            If .SelectedItems.Count <> 0 Then
                Path = .SelectedItems(1) & "\"
                Fname = Dir(Path, 7)
                
                   Fname = Dir(Path & "\*.xlsx", vbNormal)
           getwbn = Fname
           dlater = Left(getwbn, 9)
           nName = dlater
           ndir = "D:\1\" & nName & "\"
         If Dir(ndir, vbDirectory) = "" Then MkDir ndir
    
    
                Do While Fname <> ""
                    
                           Set wkb = Workbooks.Open(FileName:=Path & "\" & Fname)
     
       For Each ws In wkb.Worksheets
             
          strPDFName = ws.Name
          
          fileSaveName = ndir & ws.Name
          ws.ExportAsFixedFormat Type:=xlTypePDF, FileName:=fileSaveName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False  ', PageSetup.Orientation = xlLandscape
       Next ws
           wkb.Close False
    
                    Fname = Dir
                Loop
            End If
        End With
    End Sub

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: run time error '5" invalid procedure call or argument

    jay, in future please be specific about WHERE the error is happening? I was eventually able to duplicate the problem... but you are setting the variable Fname equal to a function? what is the purpose of "Fname = Dir" ?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: run time error '5" invalid procedure call or argument

    hi arkadi thanks for response.
    im do not to too much about programing so pl bare with me
    i do not know i found this code and altering for printing pdf file so i do not know but in original code that was there the original code was as follows
    Option Explicit 
     
    Sub GetFileNames() 
         
        Dim xRow As Long 
        Dim xDirect$, xFname$, InitialFoldr$ 
         
        InitialFoldr$ = "G:\" '<<< Startup folder to begin searching from
         
        With Application.FileDialog(msoFileDialogFolderPicker) 
            .InitialFileName = Application.DefaultFilePath & "\" 
            .Title = "Please select a folder to list Files from" 
            .InitialFileName = InitialFoldr$ 
            .Show 
            If .SelectedItems.Count <> 0 Then 
                xDirect$ = .SelectedItems(1) & "\" 
                xFname$ = Dir(xDirect$, 7) 
                Do While xFname$ <> "" 
                    ActiveCell.Offset(xRow) = xFname$ 
                    xRow = xRow + 1 
                    xFname$ = Dir 
                Loop 
            End If 
        End With 
    End Sub
    so i just add my old code in loop and i try and error to fix the prob but i stuck
    btw code find the 1st file and print in pdf but it do not pass at "Fname = dir" so
    can u pl help me thanks again

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: run time error '5" invalid procedure call or argument

    Where did this code come from? It is missing something.... xFname$ = Dir(something) but I don't know what the "something" should be yet...

    Try this (notice I added the brackets in red):

    Fname = Dir()
    Last edited by Arkadi; 05-12-2015 at 11:30 AM.

  5. #5
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: run time error '5" invalid procedure call or argument

    i try this one
     Fname = Dir(Path & "\*.xlsx", vbNormal)
    now just open 1 st file again and again code stuck at following

    For Each ws In wkb.Worksheets
                        strPDFName = ws.Name
                        fileSaveName = ndir & ws.Name
                        ws.ExportAsFixedFormat Type:=xlTypePDF, FileName:=fileSaveName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False  ', PageSetup.Orientation = xlLandscape
                    Next ws
    Last edited by jay11; 05-12-2015 at 11:44 AM.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: run time error '5" invalid procedure call or argument

    Yes your adaptation of the original code was pretty good, but does not fully work. Truth is, this is a bit more complicated. I will see what I can do and post the results.

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: run time error '5" invalid procedure call or argument

    Try this version:

    Option Explicit
    Sub aaa()
         
        Dim xRow As Long
        Dim Path, Fname, InitialFoldr$
        Dim nName As String, ndir, strPDFName, fileSaveName
        Dim wkb As Workbook
        Dim ws As Worksheet
        Dim dlater As String, getwbn
    
         
        InitialFoldr$ = "D:\" '
         
        With Application.FileDialog(msoFileDialogFolderPicker)
            .InitialFileName = Application.DefaultFilePath & "\"
            .Title = "Please select a folder to list Files from"
            .InitialFileName = InitialFoldr$
            .Show
            If .SelectedItems.Count <> 0 Then
                Path = .SelectedItems(1) & "\"
                Fname = Dir(Path & "\*.xlsx", vbNormal)
                Do While Fname <> ""
                    If Fname <> "." And Fname <> ".." Then
                        getwbn = Fname
                        dlater = Left(getwbn, 9)
                        nName = dlater
                        ndir = "D:\1\" & nName & "\"
                        If Not CreateObject("Scripting.FileSystemObject").FolderExists(ndir) Then CreateObject("Scripting.FileSystemObject").CreateFolder ndir
                        Set wkb = Workbooks.Open(Filename:=Path & "\" & Fname)
                        For Each ws In wkb.Worksheets
                            strPDFName = ws.Name
                            fileSaveName = ndir & ws.Name
                            ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fileSaveName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False  ', PageSetup.Orientation = xlLandscape
                        Next ws
                        wkb.Close False
                    End If
                    Fname = Dir()
                Loop
            End If
        End With
    End Sub

  8. #8
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: run time error '5" invalid procedure call or argument

    thanks a lot's it work great

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: run time error '5" invalid procedure call or argument

    Great jay
    Can you mark the thread as solved? Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help! Run-Time Error '5': Invalid procedure call or argument
    By capwork in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2015, 08:10 PM
  2. 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
  3. Run-time error 5, Invalid procedure call or argument
    By cmb80 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-23-2014, 08:29 AM
  4. [SOLVED] Run-time error '5': Invalid Procedure Call or Argument
    By Nikila in forum Excel General
    Replies: 2
    Last Post: 02-24-2006, 05:30 PM
  5. Run Time Error 5 - Invalid Procedure Call or Argument Q
    By John in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2005, 05:05 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