+ Reply to Thread
Results 1 to 6 of 6

Saving Workbook in newly created directory

Hybrid View

  1. #1
    Registered User
    Join Date
    06-03-2009
    Location
    California
    MS-Off Ver
    Excel 2000
    Posts
    20

    Saving Workbook in newly created directory


    I am trying to have the user hit a button and save the workbook in a newly created directory. Currently it creates the new workbook and the new directory with the correct names, however the workbook is not in the newly created directory.

    Below is the code. Any suggestions?




    
    Sub RFIFORMSave()
    
    Global rfinum As Integer    'RFI number counter or variable
    
        
        MkDir ("c:\sgreni\AnyJob\" & "some_RFI_" & rfinum)
        ChDir ("c:\sgreni\AnyJob\" & "some_RFI_" & rfinum)
        ActiveWorkbook.SaveAs Filename:="c:\sgreni\AnyJob\" & "some_RFI_" & rfinum
    
        
        this code should include after MkDir and before ChDir:
    
    
        chDirive file path! :)
    
            
    End Sub
    
    Last edited by sgreni; 06-24-2009 at 03:51 PM. Reason: solved

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Saving Workbook in newly created directory

    You don't set a Global variable within a Procedure. Try this, I haven't tested it
      Dim sPath  As String
        sPath = "c:\sgreni\AnyJob\"
        Dim rfinum As Integer
    
        rfinum = 1
        MkDir sPath & "some_RFI_" & rfinum
        ChDir sPath & "some_RFI_" & rfinum
        ActiveWorkbook.SaveAs Dir(sPath & Application.PathSeparator & "*.xls")
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-03-2009
    Location
    California
    MS-Off Ver
    Excel 2000
    Posts
    20

    Re: Saving Workbook in newly created directory

    Unfortunately this didn't work completely. The directory is created with the correct name and the workbook is saved with the correct name however the workbook is saved in "My Documents" and not in the newly created directory.

  4. #4
    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: Saving Workbook in newly created directory

    Provide an example of the saved workbook's fullname -- i.e., path and file name.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    06-03-2009
    Location
    California
    MS-Off Ver
    Excel 2000
    Posts
    20

    Re: Saving Workbook in newly created directory


    The workbook with the macros is saved at

    S:\sgreni\AnyJob\anyjob_rfiform.xls

    This subroutine is trying to create a new directory with newly saved and named workbook.

    S:\sgreni\anyjob\east_rfi_x\east_rfi_x.xls

    Currently the directory is created however the workbook "east_rfi_x.xls" is saved on c:\mydocuments

    I should also say that I am working off of the S:\ drive which is a network drive, and the C:\ drive is my local harddrive. I can assure you that I am logged in to the network and can have access and permissions.

    Any insights would be helpful. Thanks.

    Regards,

    Sterling

    global rfinum as integer 'RFI counter is global because called in multiple subs
    
    Sub RFIFORMSave()
        
        Dim sPath  As String
              
        sPath = "S:\sgreni\AnyJob\"
        
        MkDir sPath & "east_RFI_" & rfinum
        
        ChDir sPath & "east_RFI_" & rfinum
        
        ActiveWorkbook.SaveAs Filename:="east_RFI_" & rfinum
        
    
    End Sub

  6. #6
    Registered User
    Join Date
    06-03-2009
    Location
    California
    MS-Off Ver
    Excel 2000
    Posts
    20

    Re: Saving Workbook in newly created directory



    I thought I would also mention that I've tried something else. This places the newly created workbook in S:\sgreni\AnyJob\east_rfi_x.xls. Thanks again.

    
    Global rfinum As Integer    'RFI number counter or variable used in multiple subroutines
    
    Sub RFIFORMSave()
        
        Dim sPath  As String
        
        sPath = "S:\sgreni\AnyJob\"
        
        MkDir sPath & "east_RFI_" & rfinum
        
        ChDir sPath & "east_RFI_" & rfinum
        
        ActiveWorkbook.SaveAs Filename:=sPath & "east_RFI_" & rfinum
         
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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