Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Jul 2006
    Posts
    531
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA code to rename file then copy to directory (2003)

    I would like to know if it is possible in VBA to rename and file and then copy to another directory and then run access macro.

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: VBA code to rename file then copy to directory (2003)

    Yes. It's very probably possible from within your existing Access code, but I don't use Access VBA. Here are some VB resources on file manipulation:

    msdn2.microsoft.com/en-us/library/microsoft.visualbasic.filesystem_methods.aspx
    msdn2.microsoft.com/en-us/library/zfk1t850(VS.80).aspx
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    4 Star Lounger
    Join Date
    Jul 2006
    Posts
    531
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA code to rename file then copy to directory (2003)

    I think l need some guidance on the coding as am not familiar with VB very much. Could you help with the coding possibly?

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: VBA code to rename file then copy to directory (2003)

    As with some of your other recent requests, you have given no guidance as to how you'd use this in practise, but here's some starter code for you to adapt to your specific circumstances:

    Sub RenMovejj1972()
    Const strSourceFolder As String = "C:sourcefolder"
    Const strTargetFolder As String = "C:targetfolder"
    Dim strOldFileName As String
    Dim strNewFilename As String

    strOldFileName = "jj1972test.ext"

    If CBool(Len(Dir(strSourceFolder & strOldFileName))) Then ' strOldFileName in strSourceFolder exists
    strNewFilename = Left(strOldFileName, Len(strOldFileName) - 4) & Format(Date, "yyyy-mm-dd") & Right(strOldFileName, 4)
    FileCopy strSourceFolder & strOldFileName, strTargetFolder & strNewFilename
    Kill strSourceFolder & strOldFileName
    Else
    MsgBox "File " & strOldFileName & " not found"
    End If
    End Sub
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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