Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-08-2014, 08:48 AM
expert4knowledge expert4knowledge is offline macro to change name of files in a folder in order Windows 7 32bit macro to change name of files in a folder in order Office 2010 32bit
Advanced Beginner
macro to change name of files in a folder in order
 
Join Date: Apr 2012
Posts: 59
expert4knowledge is on a distinguished road
Default macro to change name of files in a folder in order


Hello all, II have a macro that whenever I run it, it save the file in PDF format with the date and a number, the files are invoices, I wrote a macro and it works nice except one thing. When I run the macro and it save the file for example witht the format invoice-130001-07/08/2014, (the PDF starts from 130000) and the 9th generated file that is the last generated file of the day has the name invoice-130009-07/08/2014 but but when I save it in the next day, logically it must be invoice-130010-08/08/2014 but it starts again from 130001 for the number and macro generates the name invoice-130001-08/08/2014 I want to know if there is anyway to fix it?
The code is here and the file is attached:
Code:
Sub quote13000() 
     '
    Dim exdate As Date 
    Dim o As Object 
    Dim odoc As Document 
    Dim nm, nm1 As String 
    Dim i As Integer 
    Dim PathAndFileName As String, n As Long 
    Set odoc = ActiveDocument 
    n = 3000 
    PathAndFileName = "C:\Users\Tony\Documents\Quotes\Quote 1" 
    If Dir(PathAndFileName & n & " " & Format(Now, "mm-dd-yy") & ".pdf") = "" Then 
        nm = PathAndFileName & n & " " & Format(Now, "mm-dd-yy") & ".pdf" 
        With ActiveDocument 
            .SaveAs FileName:=nm, _ 
            Fileformat:=wdFormatPDF 
             '.Close
        End With 
    Else 
        n = 3000 
        Do While Dir(PathAndFileName & n & " " & Format(Now, "mm-dd-yy") & ".pdf") <> "" 
            n = n + 1 
        Loop 
        nm = PathAndFileName & n & " " & Format(Now, "mm-dd-yy") & ".pdf" 
        With ActiveDocument 
            .SaveAs FileName:=nm, _ 
            Fileformat:=wdFormatPDF 
             ' .Close
        End With 
    End If 
End Sub
Attached Files
File Type: zip wordmacro2.zip (22.8 KB, 7 views)

Last edited by macropod; 07-08-2014 at 03:13 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 07-08-2014, 03:20 PM
macropod's Avatar
macropod macropod is offline macro to change name of files in a folder in order Windows 7 32bit macro to change name of files in a folder in order Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Unless you store and retrieve the last-used number, the only way the macro could pick up where it left off is to test the numbers of all the files produced in previous iterations, to see what the highest number is. For some approaches to that, see the links in this post: https://www.msofficeforums.com/word/...mber-word.html

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-09-2014, 01:38 PM
expert4knowledge expert4knowledge is offline macro to change name of files in a folder in order Windows 7 32bit macro to change name of files in a folder in order Office 2010 32bit
Advanced Beginner
macro to change name of files in a folder in order
 
Join Date: Apr 2012
Posts: 59
expert4knowledge is on a distinguished road
Default

I used the procedure mentioned in the following link and combined it with my code:
https://www.msofficeforums.com/word/...iple-docs.html
But it seems that it is not working. I think the idea of saving the last number is good but where can I save it? The document property seems does not working in my file? I put it in the header to be able to remove the colour and make it sightless, attached is the file. BTW thanks for putting the code in appropriate tags since I could not see it at the first.
I think I should try to find the answer to question What other ways can I save the last generated number?
Attached Files
File Type: zip wordmacro4docm.zip (26.3 KB, 8 views)
Reply With Quote
  #4  
Old 07-09-2014, 04:41 PM
macropod's Avatar
macropod macropod is offline macro to change name of files in a folder in order Windows 7 32bit macro to change name of files in a folder in order Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Without wanting to place too fine a point on it, there is no DOCPROPERTY field referencing InvNum in your document. All you have is a '{DOCPROPERTY InvNum}' text string. That is not a field.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-10-2014, 03:27 PM
expert4knowledge expert4knowledge is offline macro to change name of files in a folder in order Windows 7 32bit macro to change name of files in a folder in order Office 2010 32bit
Advanced Beginner
macro to change name of files in a folder in order
 
Join Date: Apr 2012
Posts: 59
expert4knowledge is on a distinguished road
Default

How can I put a field to it? May I ask you tell a reference for me so I learn how to do it?
Reply With Quote
  #6  
Old 07-10-2014, 03:54 PM
macropod's Avatar
macropod macropod is offline macro to change name of files in a folder in order Windows 7 32bit macro to change name of files in a folder in order Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Delete the {} from your '{DOCPROPERTY InvNum}', then select 'DOCPROPERTY InvNum' and press Ctrl-F9. Press F9 again to update the field.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
save as pdf in order



Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to change name of files in a folder in order How do I change the page number order? officeboy09 Excel 4 10-30-2013 08:11 PM
macro to change name of files in a folder in order Word Macro - change date in footer for all files in a folder patidallas22 Word VBA 2 03-09-2012 08:14 AM
O 2007 folders & files lose alphabetical order in John Seed Outlook 0 02-28-2012 05:56 PM
macro to change name of files in a folder in order 2010 Office -- Favorites folder not staying in order. Emerogork Outlook 9 08-13-2011 07:00 AM
macro to change name of files in a folder in order Change order of names to LAST / FIRST ? Jack R Outlook 1 07-05-2010 08:50 PM

Other Forums: Access Forums

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


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