+ Reply to Thread
Results 1 to 5 of 5

syntax error with Expected:= error

Hybrid View

  1. #1
    Registered User
    Join Date
    04-18-2013
    Location
    hacienda heights, ca
    MS-Off Ver
    Excel 2007 / Excel 2010
    Posts
    43

    syntax error with Expected:= error

    I was pointed in a direction on what I could change in my code that I have been working on but with the changes I am getting 2 different errors. The errors I am receiving are the following, One error is a compile error: syntax error and the other is compile error: Expected:=.

    This is the code I am working with right now. The coding in red is my issue I think
    Sub PDFPageNumbers()
        Dim FSO As Object
        Dim F_Folder As Object
        Dim F_File As Object
        Dim IterateFolders As String  'I added this in trying to figure the issue out
        Dim Selected_Items As String
        Dim DialogFolder As FileDialog
        Dim Acrobat_File As Acrobat.AcroPDDoc
        Dim i As Long
     
        'Select PDF Directory
        Set DialogFolder = Application.FileDialog(msoFileDialogFolderPicker)
        If DialogFolder.Show = -1 Then
            Selected_Items = DialogFolder.SelectedItems(1)
        Else: Set DialogFolder = Nothing
        End If
        Set DialogFolder = Nothing
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set F_Folder = FSO.GetFolder(Selected_Items)
             IterateFolders(F_Folder, i)
            i = 2
           Sub IterateFolders(ByVal F_Folder, ByRef i)
            For Each SubFolder In F_Folder
                IterateFolders(SubFolder, i)
        Next
            For Each F_File In F_Folder.Files
                Selected_Items = UCase(F_File.Path)
                    If Right(Selected_Items, 4) = ".PDF" Then
                    Set Acrobat_File = New Acrobat.AcroPDDoc
                    Acrobat_File.Open Selected_Items
                    Cells(i, 1).Value = Selected_Items
                    Cells(i, 2).Value = Acrobat_File.GetNumPages
                    i = i + 1
                    Acrobat_File.Close
                Set Acrobat_File = Nothing
            End If
        Next
    End Sub
     
        Range("A:B").Columns.AutoFit
     
        Set F_File = Nothing
        Set F_Folder = Nothing
        Set FSO = Nothing
     
    End Sub
    This is the original code, the code in blue is what I cut out
    Sub PDFPageNumbers()
        Dim FSO As Object
        Dim F_Folder As Object
        Dim F_File As Object
        Dim Selected_Items As String
        Dim DialogFolder As FileDialog
        Dim Acrobat_File As Acrobat.AcroPDDoc
        Dim i As Long
     
        'Select PDF Directory
        Set DialogFolder = Application.FileDialog(msoFileDialogFolderPicker)
        If DialogFolder.Show = -1 Then
            Selected_Items = DialogFolder.SelectedItems(1)
        Else: Set DialogFolder = Nothing
        End If
        Set DialogFolder = Nothing
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set F_Folder = FSO.GetFolder(Selected_Items)
        i = 2
        For Each F_File In F_Folder.Files
            Selected_Items = UCase(F_File.Path)
            If Right(Selected_Items, 4) = ".PDF" Then
                Set Acrobat_File = New Acrobat.AcroPDDoc
                Acrobat_File.Open Selected_Items
                Cells(i, 1).Value = Selected_Items
                Cells(i, 2).Value = Acrobat_File.GetNumPages
                i = i + 1
                Acrobat_File.Close
                Set Acrobat_File = Nothing
            End If
        Next
     
        Range("A:B").Columns.AutoFit
     
        Set F_File = Nothing
        Set F_Folder = Nothing
        Set FSO = Nothing
     
    End Sub

    This is the code that I pasted in.
      Set F_Folder = FSO.GetFolder(Selected_Items)
        IterateFolders(F_Folder, i)
    .....
     
    Sub IterateFolders(ByVal F_Folder, ByRef i)
        For Each SubFolder In F_Folder
            IterateFolders(SubFolder, i)
        Next
        For Each F_File In F_Folder.Files
            Selected_Items = UCase(F_File.Path)
            If Right(Selected_Items, 4) = ".PDF" Then
                Set Acrobat_File = New Acrobat.AcroPDDoc
                Acrobat_File.Open Selected_Items
                Cells(i, 1).Value = Selected_Items
                Cells(i, 2).Value = Acrobat_File.GetNumPages
                i = i + 1
                Acrobat_File.Close
                Set Acrobat_File = Nothing
            End If
        Next
    End Sub
    I don't think IterateFolders is defined. I am confused.

    Thanks for the help.

  2. #2
    Forum Contributor
    Join Date
    12-31-2012
    Location
    Jhang, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: syntax error with Expected:= error

    Use parameters without parentheses

    Wrong:
    IterateFolders(F_Folder, i)
    Correct:
    IterateFolders F_Folder, i

  3. #3
    Registered User
    Join Date
    04-18-2013
    Location
    hacienda heights, ca
    MS-Off Ver
    Excel 2007 / Excel 2010
    Posts
    43

    Re: syntax error with Expected:= error

    Ok I change what was suggested and now I am coming up with a different error.
    IterateFolders F_Folder, i
    Compile error:
    Expected Sub, Function, or Property

    This is having IterateFolders as a String, but when I change it to an Object the error changes to

    Compile error:
    Expected End Sub
    At this line of code
    i = 2
    I wish I had a better grasp at VBA.

  4. #4
    Registered User
    Join Date
    04-18-2013
    Location
    hacienda heights, ca
    MS-Off Ver
    Excel 2007 / Excel 2010
    Posts
    43

    Re: syntax error with Expected:= error

    I have tried looking up other methods and still not getting anywhere. Am I missing something simple?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: syntax error with Expected:= error

    As your code is written, IterateFolders is a procedure. Did you write a procedure by that name?
    Entia non sunt multiplicanda sine necessitate

+ 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. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  2. Receiving following error “Complie error : syntax error” Help
    By masond3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-02-2012, 10:19 AM
  3. [SOLVED] Compile Error: Expected Expression, Syntax Error
    By gjohn282 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2012, 11:28 PM
  4. Syntax Error and Compile Error: Expected Line Number or Label...
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2011, 09:59 AM
  5. VBA compilation error : expected expression error
    By raknahs in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-21-2010, 12:57 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