![]() |
#1
|
|||
|
|||
![]()
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 |
#2
|
||||
|
||||
![]()
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 |
#3
|
|||
|
|||
![]()
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?
|
![]() |
|
![]() |
||||
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 |
![]() |
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 |