Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-12-2017, 09:04 AM
andrbea andrbea is offline Save the same file with different name 35 times Windows 7 64bit Save the same file with different name 35 times Office 2010 64bit
Novice
Save the same file with different name 35 times
 
Join Date: Nov 2017
Posts: 4
andrbea is on a distinguished road
Default 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)
Reply With Quote
  #2  
Old 11-12-2017, 10:16 PM
gmayor's Avatar
gmayor gmayor is offline Save the same file with different name 35 times Windows 10 Save the same file with different name 35 times Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

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
Reply With Quote
  #3  
Old 11-13-2017, 02:23 AM
andrbea andrbea is offline Save the same file with different name 35 times Windows 7 64bit Save the same file with different name 35 times Office 2010 64bit
Novice
Save the same file with different name 35 times
 
Join Date: Nov 2017
Posts: 4
andrbea is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 11-13-2017, 02:43 AM
gmayor's Avatar
gmayor gmayor is offline Save the same file with different name 35 times Windows 10 Save the same file with different name 35 times Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

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
Reply With Quote
  #5  
Old 11-13-2017, 03:00 AM
andrbea andrbea is offline Save the same file with different name 35 times Windows 7 64bit Save the same file with different name 35 times Office 2010 64bit
Novice
Save the same file with different name 35 times
 
Join Date: Nov 2017
Posts: 4
andrbea is on a distinguished road
Default

ok will have a go at the process for dummies this evening
Many tks
Reply With Quote
  #6  
Old 11-13-2017, 10:50 AM
andrbea andrbea is offline Save the same file with different name 35 times Windows 7 64bit Save the same file with different name 35 times Office 2010 64bit
Novice
Save the same file with different name 35 times
 
Join Date: Nov 2017
Posts: 4
andrbea is on a distinguished road
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save the same file with different name 35 times 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
Save the same file with different name 35 times vba code for folder name, subfolder directory, file name & revision times klpw Excel Programming 2 12-24-2015 12:31 AM
Save the same file with different name 35 times save dialog box promt doesn't save file brmveen Word VBA 2 11-04-2015 12:51 AM
Save the same file with different name 35 times 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:56 AM.


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