+ Reply to Thread
Results 1 to 3 of 3

Why is my VBA code creating a file in the Documents folder?

  1. #1
    Registered User
    Join Date
    03-25-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    61

    Why is my VBA code creating a file in the Documents folder?

    I have almost no VBA knowledge, so hopefully this is an easy error for real experts to spot!

    My code below is working OK, except that the file "Output.xls" is being created in the PC's Documents folder rather in the specified folder. I can't figure out why!

    Thanks in advance for your help!

    --------

    Sub AllFiles()
    Dim folderPath As String
    Dim filename As String
    Dim wb As Workbook

    folderPath = "C:\Output\Macrofiles\" 'change to suit

    If Right(folderPath, 1) <> "\" Then folderPath = folderPath + "\"

    Set OutputBook = Workbooks.Add '' Creates the output.xls workbook for pasting all the data into
    With OutputBook
    .SaveAs filename:="Output.xls"
    End With

    filename = Dir(folderPath & "*.xls")
    Do While filename <> ""
    Application.ScreenUpdating = False
    Set wb = Workbooks.Open(folderPath & filename)

    'Call a subroutine here to operate on the just-opened workbook
    Call DataGrabber

    wb.Close False
    filename = Dir
    Loop
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Why is my VBA code creating a file in the Documents folder?

    Try

    Please Login or Register  to view this content.
    Martin

  3. #3
    Registered User
    Join Date
    03-25-2013
    Location
    New York
    MS-Off Ver
    Excel 2010
    Posts
    61

    Re: Why is my VBA code creating a file in the Documents folder?

    Perfect, thank you!

+ 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 VBA code to read from Word documents in a folder and Print it to Excel
    By Vinod Krishna.C in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2013, 11:04 PM
  2. [SOLVED] Code to print all word documents from a folder
    By Scal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2013, 04:44 PM
  3. [SOLVED] Need code to save file to new folder, erase from old folder
    By Ron M. in forum Excel General
    Replies: 1
    Last Post: 02-24-2006, 02:10 PM
  4. excel documents won't open from my documents folder
    By Paul1961 in forum Excel General
    Replies: 2
    Last Post: 01-15-2006, 01:35 PM
  5. Creating Folder Folder in My Documents VBA - HELP
    By Ali in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2005, 10:05 AM

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