+ Reply to Thread
Results 1 to 5 of 5

Help with Set f = fso.Getfolder

  1. #1
    Registered User
    Join Date
    10-18-2010
    Location
    NJ
    MS-Off Ver
    Excel 2007
    Posts
    73

    Help with Set f = fso.Getfolder

    I have the following macro that takes a worksheet from the active file and inserts it into every workbook within a specific folder. Does anyone know how I can update this code so it works for other people as long as they have the folder called "Comp File Split" on their desktop? Right now it will only work for me since my desktop path is hard coded into the macro. I've highlighted the portion in question.

    Sub AddTabIG()
    '
    'Add Tab called "Budget Rates"

    Dim SrcBook As Workbook
    Dim fso As Object 'File System Object
    Dim f As Object 'Folder
    Dim ff As Object 'Folder Files
    Dim f1 As Object 'File to add template sheet
    Dim fst As Object 'template worksheet

    Application.ScreenUpdating = False
    Set fst = ThisWorkbook.Worksheets("Budget Rates")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.Getfolder("C:\users\SteveP\Desktop\Comp File Split\")
    Set ff = f.Files

    For Each f1 In ff
    Set SrcBook = Workbooks.Open(f1)
    'object reference
    fst.Copy After:=SrcBook.Worksheets(1)
    'copy template sheet
    SrcBook.Worksheets(1).Activate
    'activate first worksheet
    SrcBook.Close True
    'close file saving without prompt
    Next
    Application.ScreenUpdating = True
    Set SrcBook = Nothing 'release system resources
    Set fst = Nothing
    Set fso = Nothing
    Set f = Nothing
    Set ff = Nothing

    End Sub

    Thanks,
    Steve
    Last edited by stevetothink; 11-06-2013 at 11:42 AM.

  2. #2
    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: Help with Set f = fso.Getfolder

    Please Login or Register  to view this content.
    Please edit your post to add CODE tags.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    10-18-2010
    Location
    NJ
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: Help with Set f = fso.Getfolder

    Thank you for this. It works perfectly.

    Since the files are password protected (same password for all file), it prompts me to enter the password for each file. Do you know how I would update my code above so it automatically enters the password "ABC123" and then performs the rest of the Macro?

    Thanks,
    Steve

    Quote Originally Posted by shg View Post
    Please Login or Register  to view this content.
    Please edit your post to add CODE tags.

  4. #4
    Registered User
    Join Date
    10-18-2010
    Location
    NJ
    MS-Off Ver
    Excel 2007
    Posts
    73

    Re: Help with Set f = fso.Getfolder

    I figured out how to do this.

    Set SrcBook = Workbooks.Open(f1,,,,"password")

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Help with Set f = fso.Getfolder

    you may find it easier to use named arguments rather than positional ones
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

+ 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. [SOLVED] GetFolder Method of FileSystemObject Fails On Second Pass
    By goss in forum Excel General
    Replies: 4
    Last Post: 11-14-2012, 01:27 PM
  2. Textbox.text to .getfolder(filename)
    By ozan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-09-2012, 10:37 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