Consulting

Results 1 to 3 of 3

Thread: Validate startup path

  1. #1

    Validate startup path

    Hello,

    I'd like to insure that an authorized workbook on a network drive is the one being opened. Sometimes people will copy a workbook from the network to their desktop or their mydocuments folder, and now if I update information they will no longer have the current version.

    This what I have tested today;

    [vba]Sub Auto_Open()
    If Application.StartupPath <> "c:\" & ThisWorkbook.Name & ".xls" Then
    MsgBox ("you have opened this workbook in an invalid location.")
    ThisWorkbook.Close
    End If

    End Sub[/vba]

    However, the startuppath is not what I desire. Should I be looking at workbook.fullname and then parse the path minus the workbook name to see if it has been opened from the desired directory.

    Thank you

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub TestOpen()
    Dim Correct As String
    Correct = "S:\Server\MyFolder\"
    If Split(ActiveWorkbook.FullName, ActiveWorkbook.Name)(0) <> Correct Then
    MsgBox "Please open from " & Correct
    End If

    End Sub[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Thanks mdmack, I think that is the general diection I was headed in, but it was not as clean and concise.

Posting Permissions

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