Consulting

Results 1 to 4 of 4

Thread: Problem With Macro

  1. #1
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    2
    Location

    Problem With Macro

    Hi,

    below my Macro:

    Sub AllFiles()
        Dim folderPath As String
        Dim filename As String
        Dim wb As Workbook
      
        folderPath = "C:\Users\Dom\Desktop\Bob"
        
        If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"
        
        filename = Dir(folderPath & "*.csv")
        Do While filename <> ""
          Application.ScreenUpdating = False
            Set wb = Workbooks.Open(folderPath, Local:=True & filename)
             
    
    
            Call ChangeFile
            
            
            filename = Dir
        Loop
      Application.ScreenUpdating = True
    End Sub
    I need to open CSV file with data like Excel, so I wrote Local:=True, but then i have error:"run time error 1004 method open of object workbooks failed"

    Any help is greatly appreciated!!
    Last edited by Paul_Hossler; 01-17-2018 at 05:40 PM.

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    832
    Location
    If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
    Note the "&" HTH. Dave
    edit: Welcome to this forum!

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Yes, welcome to the forum

    I added CODE tags around your macro for formatting, but the next time you can use the [#] icon to insert the CODE and /CODE tags and paste your macro(s) between them
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    2
    Location
    Thank you I found solution.

Posting Permissions

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