Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-16-2023, 11:00 PM
Dimsok Dimsok is offline Copy document to a few places Windows XP Copy document to a few places Office 2007
Advanced Beginner
Copy document to a few places
 
Join Date: Sep 2014
Location: exUSSR
Posts: 50
Dimsok is on a distinguished road
Default Copy document to a few places

I have such code for copy document to root C


Code:
Sub FileCopyToС()
    OrigLongFileName = ActiveDocument.Name
    OldPath = ActiveDocument.Path & Application.PathSeparator
        Documents(ActiveWindow.Caption).Close
        FileCopy OldPath & OrigLongFileName, "C:\" & OrigLongFileName
        Documents.Open FileName:=OldPath & OrigLongFileName
        Application.GoBack
End Sub
How to change it (or create new), that documents will copy without closing and opening? I want to make backups to few places (with replacing old on that pathes). For example, from "C:\My doc\File.docx" to such pathes: "F:\My doc\File.docx" "G:\My doc\File.docx" "H:\My doc\File.docx" "H:\My doc\File.docx". But don't want see everytime during it 4 times closing and opening active document. Is it possible to copy current document silently? Don't see anything during coping, just like in normal saving.
Reply With Quote
  #2  
Old 04-17-2023, 07:27 AM
gmayor's Avatar
gmayor gmayor is offline Copy document to a few places Windows 10 Copy document to a few places Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Try the following:


Code:
Sub FileCopyTo()
Dim sName As String, sOriginal As String
Dim vPath() As Variant
Dim i As Integer
    vPath = Array("C:\My doc\", "F:\My doc\", "G:\My doc\", "H:\My doc\")
    ActiveDocument.Save
    sOriginal = ActiveDocument.FullName
    sName = ActiveDocument.Name
    For i = 0 To UBound(vPath)
        If FolderExists(CStr(vPath(i))) Then
            ActiveDocument.SaveAs2 FileName:=CStr(vPath(i)) & sName, FileFormat:=wdFormatXMLDocument
        End If
    Next i
    ActiveDocument.SaveAs2 FileName:=sOriginal, FileFormat:=wdFormatXMLDocument
End Sub

Private Function FolderExists(strFolderName As String) As Boolean
'Graham Mayor
'strFolderName is the name of folder to check
Dim FSO As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    If (FSO.FolderExists(strFolderName)) Then
        FolderExists = True
    Else
        FolderExists = False
    End If
lbl_Exit:
    Set FSO = Nothing
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 04-23-2023, 10:20 PM
Dimsok Dimsok is offline Copy document to a few places Windows XP Copy document to a few places Office 2007
Advanced Beginner
Copy document to a few places
 
Join Date: Sep 2014
Location: exUSSR
Posts: 50
Dimsok is on a distinguished road
Default

Also got to use "SaveAs Filename" instead of "SaveAs2 FileName" as in my previous topic. It also save original document, but i don't want it - just copy it to other places. Try to delete ActiveDocument.Save, but it saves anyway. Other issue - i compare documents, which had been copied, and they all have different hashes. Is there any possibility to copy them that they will be identical, like i copied them in file browser? For example, i try FileCopy "c:\1.docx", "c:\2.docx". They are identical, but can you provide a code, which do it with active document to a few places, which i have posted?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting text fragments in multiple places of document (Word 2007). fieloryb Word 3 05-16-2023 11:10 PM
Copy a selected range of a document to a new document with preserving formatting,header and footer RobertDany Word VBA 10 08-10-2021 04:04 AM
Copy document to a few places Copy selected text from one document and paste to new document in same position on the page gasparik Word VBA 1 05-11-2020 05:41 AM
Need to Selectively Merge Records to Different Places in a Word Directory-type Document TotheMoonAlice Mail Merge 3 03-27-2015 08:11 AM
in 2013, cannot format 4 dec places in Word Document Abacus1234 Mail Merge 3 10-23-2013 03:57 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:51 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft