Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    Rename word document during copy/paste

    The works I知 doing now are following on from this:


    https://www.accessforums.net/showthr...3&goto=newpost

    I知 creating a system to manage risk assessments for locations. So, I now have the code to add to a template document. What I now want to do is Copy a template. Paste it in the right location with a new name (using variables from record source.) I have the majority of this complete in one form or another and I知 sure I will be able to tie it all together.

    One-part I知 struggling with is defining the name when the file is pasted.

    I could paste the file and use VBA to rename, I was wondering if it痴 possible to define the name as you paste?

    This is some test code I知 using which does copy and paste a file:


    Code:
    Private Sub Command93_Click()
    Dim FSO
    Dim sFile As String
    Dim sSFolder As String
    Dim sDFolder As String
    
    'This is Your File Name which you want to Copy
    sFile = "RAM_Template.docx"
    
    'Change to match the source folder path
    sSFolder = "\\*****SERVER\general\****** Documents\!Managment\VBA_Templates_do_not_modify\"
    
    'Change to match the destination folder path
    sDFolder = "\\*******SERVER\general\RAMS\*****_RAMS\"
    
    'Create Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    'Checking If File Is Located in the Source Folder
    If Not FSO.FileExists(sSFolder & sFile) Then
        MsgBox "Specified File Not Found", vbInformation, "Not Found"
        
    'Copying If the Same File is Not Located in the Destination Folder
    ElseIf Not FSO.FileExists(sDFolder & sFile) Then
        FSO.CopyFile (sSFolder & sFile), sDFolder, True
        MsgBox "Specified File Copied Successfully", vbInformation, "Done!"
    Else
        MsgBox "Specified File Already Exists In The Destination Folder", vbExclamation, "File Already Exists"
    End If
    
    
    End Sub
    The more I think about it the more im convinced that paste and rename is the only option.

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    you can change the name with copyfile

    e.g.

    source="C:\template.txt"
    destination="C:\usercopy.txt"

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    That easy, who knew!

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    just google the use of copyfile, its all out there

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 06-27-2017, 12:06 PM
  2. Replies: 4
    Last Post: 08-24-2015, 12:57 PM
  3. Replies: 6
    Last Post: 08-16-2014, 11:20 AM
  4. Copy/paste/rename a field in the same form?
    By Jamesiv1 in forum Access
    Replies: 5
    Last Post: 04-26-2014, 10:22 AM
  5. Copy & Rename a report
    By Juanna_v in forum Reports
    Replies: 25
    Last Post: 02-17-2011, 12:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums