Consulting

Results 1 to 6 of 6

Thread: Solved: Here's a challenging one to do with saving

  1. #1
    Knowledge Base Approver
    Space Cadet
    VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location

    Solved: Here's a challenging one to do with saving

    I posted earlier today on how to save within a macro and thankfully with help from DRJ that problem is a thing of the past.

    My new conundrum is how to save the documents using the description prescribed by our office manual as well as adding a unique identifier in case of same descriptions given to documents?

    I was thinking of using a time stamp but the PCs on the network are not completely sync-ed so that may create name conflicts on the documents drive.

    Any ideas, suggestions etc would be greatly appreciated

    [VBA] Sub SaveTheDoc(sFileSaved As Boolean, Optional sChangename As Boolean = False)
    Dim DocDescrip As String
    If Not sFileSaved Or sChangename Then
    'Docdescrip is the user created description of the document
    DocDescrip = InputBox("Please enter a description of the document save as", "SAVING DOCUMENT")
    While Len(DocDescrip) = 0
    DocDescrip = InputBox("Please enter a description of the document save as", "SAVING DOCUMENT")
    Wend
    'i need to add a unique identifeier to the end of it but am not sure how
    DocDescrip = docsPath + getDirectory(selectDirectory) + DocDescrip
    ActiveDocument.SaveAs FileName:=DocDescrip
    ActiveDocument.AttachedTemplate.Saved = True
    Else
    ActiveDocument.Save
    End If
    End Sub [/VBA]

    Thanks in advance
    Andrew;?

  2. #2
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Andrew,
    I use the following in an automated routine to check for previous name and increment a suffix. Direct, SaveName and SaveAsName are my variables for the path and file
    MD

    [VBA]
    With Application.FileSearch
    .NewSearch
    .LookIn = Direct
    .SearchSubFolders = False
    .FileName = SaveAsName
    .FileType = msoFileTypeAllFiles
    If .Execute() > 0 Then
    SaveAsName = SaveName & "-" & .FoundFiles.Count & ".doc"
    End If
    End With
    [/VBA]

    In writing up for the KB, the foregoing code doid not work as required in 2003, and the following variation was used instead.

    [VBA]
    'Check for previous instances of the SaveName, if found add incremental suffix
    With Application.FileSearch
    .NewSearch
    .LookIn = Direct
    .SearchSubFolders = False
    .FileName = SaveName & "*"
    .FileType = msoFileTypeAllFiles
    If .Execute() > 0 Then
    SaveAsName = SaveName & "-" & .FoundFiles.Count & ".doc"
    End If
    End With

    [/VBA]
    Last edited by mdmackillop; 02-10-2005 at 06:02 PM. Reason: Update for 2003

  3. #3
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location

    thats perfect

    As a law firm documents carry similar nomenclature so i'll pitch this to my boss and se what he thinks (I think its cool), he's hinted at using a Global Unique ID (GUID) - do you have any experience in working with this?

  4. #4
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    He liked it (no GUID thank goodness). Thanks for the help

    Andrew;?

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    The only familiarity I have with it is the good old Scottish phrase
    Nae bloody guid!

    I've put my mailmerge and autofiling routine, which may be of interest, as a KB entry, which hopefully will be approved shortly

  6. #6
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    cool. i'm sure it will.

    Thanks again for the help, my biggest failing with macro writing is knowing what I want to do and convincing VBA to act like VB .net to do it instead of working with Word

Posting Permissions

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