Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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, 9 views)

Last edited by macropod; 07-08-2014 at 03:13 PM. Reason: Added code tags & formatting
Reply With Quote
 

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 10:29 AM.


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