Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Glasgow, Scotland
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Created Today

    I have created a very simple module that saves a file into a specific folder (CATARNS) with the format PRDDMM.doc eg PR1605.doc. I now want to do two things.

    1. I want to save the file as HTM instead.
    2. I want to create a module to check if a file already exists under the folder CataRNS with today's date, DDMM, if it does I want to create a file PR1605a.doc, if this already exists as well I want it to create a file PR1605b.doc and so on.

    Can anyone help me please

    Many thanks

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: File Created Today

    I have not much experience (none actually) of saving HTML formats but the following should work for you. <pre>Sub SavePRFile()
    Dim fName As String
    Dim fIndx As Integer
    Dim NameExists As Boolean
    fIndx = 97
    NameExists = True
    Do
    fName = "CATARNSPR" & Format(Now(), "DDMM") & Chr(fIndx) & ".htm"
    If Dir(fName) <> "" Then
    fIndx = fIndx + 1
    Else
    NameExists = False
    End If
    Loop Until NameExists = False
    ActiveDocument.SaveAs FileName:=fName, FileFormat:=wdFormatHTML
    End Sub</pre>

    It starts with a file name based on the e.g. PR2105a and saves it as required, and increments the ending letter for each save. There is no check included to deal with letetrs beyond z, so if that is an issue it could be looked at. Also it presuposses the existence of the CATARNS directory.

    Andrew C

  3. #3
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Reading/Swindon, Berkshire, United Kingdom
    Posts
    664
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Created Today

    FWIW,

    and on the off-chance it might be useful to someone, I use the following system on files I'm saving several times a day. This avoids the need to check for the index that Andrew has created and gives me the time of day that the file was created - which does actually prove a useful bit of info on occaision. You could probably cut the "ss" out of the format statement but I tripped up once or twice and just keep it there because it works for me. However, it does lead to longer filenames but I can live with that.

    fName = "CATARNSPR" & Format(Now(), "yyyymmddhhmmss") & ".htm"

    Brooke

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Glasgow, Scotland
    Posts
    137
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Created Today

    Andrew, many thanks it worked a treat.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •