#1
|
|||
|
|||
Save the same file with different name 35 times
For a client's upload platform (for invoices) I have to send unique details, monthly, eg 35 times. The file in enclosure (it lists all the 35 invoices, giving 6 data fields in a row, per FW-number) This master file (per month) has the same content (about 3 pages long). but the client wants a unique title-name for the file for each ticket created. So I bring up the 3-page master file in Word and save it as FW1. then save it as FW2, then save it as FW 3 etc up to FW 35. Then I go to the Client's platform. Fill in 12 fields per work order (other unique data he needs) and then add the file title eg FW3.
Is there a way to run a macro on the Word master file and interactively fill in the file range for the title, eg FW1 then ending at FW35. Then the macro writes these files to one Word folder (called 02.10). Then, on his online platform, I can access the Word folder (this is already fuunctioning) to pick the files, which have already been created (FW1-FW35). Saving me the boring job of creating them manually, with save as FW 35, for example. I just want a macro to save 35 files in 1 go, with titles FW1 running till FW35. Anotyher month the first letters might be different, XL1 to XL 46, but always 2 letters and a fixed number of files (max 60) |
#2
|
||||
|
||||
If I understand the requirement correctly, save the first document as FW1.docx or XL1.docx or whatever in the folder of choice and then run the following macro to make the prompted number of identical documents in the same folder
Code:
Sub CopyDocs() 'Graham Mayor - http://www.gmayor.com - Last updated - 13 Nov 2017 Dim oDoc As Document Dim strName As String Dim strExt As String Dim strPath As String Dim iNum As Integer Dim fso As Object Set oDoc = ActiveDocument If Not oDoc.Path = "" Then strExt = Mid(oDoc.Name, InStrRev(oDoc.Name, Chr(46))) If Len(oDoc.Name) = 3 + Len(strExt) And Mid(oDoc.Name, 3, 1) = "1" Then strPath = oDoc.Path & Chr(92) strName = Left(oDoc.Name, 2) Set fso = CreateObject("Scripting.FileSystemObject") For iNum = 2 To InputBox("Enter the total number of documents to be created", , 35) fso.CopyFile strPath & strName & "1" & strExt, strPath & strName & CStr(iNum) & strExt Next iNum Else MsgBox "Filename in the wrong format!" End If Else MsgBox "Document not saved." End If MsgBox iNum - 1 & " copies created" lbl_Exit: Set oDoc = Nothing Set fso = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
I have a macro file now (called creator1), with the lines
Sub CopyDocs() 'Graham Mayor - http://www.gmayor.com - Last updated - 13 Nov 2017 Dim oDoc As Document Dim strName As String Dim strExt As String Dim strPath As String Dim iNum As Integer Dim fso As Object Set oDoc = ActiveDocument If Not oDoc.Path = "" Then strExt = Mid(oDoc.Name, InStrRev(oDoc.Name, Chr(46))) If Len(oDoc.Name) = 3 + Len(strExt) And Mid(oDoc.Name, 3, 1) = "1" Then strPath = oDoc.Path & Chr(92) strName = Left(oDoc.Name, 2) Set fso = CreateObject("Scripting.FileSystemObject") For iNum = 2 To InputBox("Enter the total number of documents to be created", , 35) fso.CopyFile strPath & strName & "1" & strExt, strPath & strName & CStr(iNum) & strExt Next iNum Else MsgBox "Filename in the wrong format!" End If Else MsgBox "Document not saved." End If MsgBox iNum - 1 & " copies created" lbl_Exit: Set oDoc = Nothing Set fso = Nothing Exit Sub End Sub If I create 1st file, save it as XG1, then execute the macro (it shows up in the dropdown menu, as creator1), the result, in the word file is that the content of the macro just gets written in another file (the code itself) what am I doing wrong? Tks for writing the macro by the way. But how do I get it to work? I used the tab view - record macro - pasted your code - stop recording macro |
#4
|
||||
|
||||
The macro is called CopyDocs
See http://www.gmayor.com/installing_macro.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
ok will have a go at the process for dummies this evening
Many tks |
#6
|
|||
|
|||
The copyDocs macro worked
after making a master file XT1 I asked for 5 docs and on opening the destination file (02.10) there they were XT2 thru' XT6 Fantastic, many thanks I have an icon button to show the macros, and choose Copydocs after opening the XT1 file, ready for copying |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Save document multiple times with date as filename | JonniBravo | Word | 6 | 03-13-2017 11:35 AM |
ics file - issue with times | Officer_Bierschnitt | Excel Programming | 0 | 10-06-2016 01:52 AM |
vba code for folder name, subfolder directory, file name & revision times | klpw | Excel Programming | 2 | 12-24-2015 12:31 AM |
save dialog box promt doesn't save file | brmveen | Word VBA | 2 | 11-04-2015 12:51 AM |
error: You are attempting to save a file format that is blocked by file block setting | zatlas1 | Office | 8 | 04-28-2012 02:37 PM |