+ Reply to Thread
Results 1 to 3 of 3

Verifying path fails for no apparent reason..Clueless

  1. #1

    Verifying path fails for no apparent reason..Clueless

    Hi

    What I want to do is to ensure that the workbook is opened only from
    the designated folder, in this case it is a folder in a mapped network
    drive P:\. The code works as intended if I try to open the workbook
    from my C:\ drive, ie. the workbook closes showing the message box. The
    code is:

    Const ServerPath As String = "P:\Documents and Settings\All
    Users\Documents"

    Private Sub Workbook_Open()
    If ThisWorkbook.Path <> SeverPath Then
    MsgBox "You are not allowed to open the workbook from the
    current location"
    ThisWorkbook.Close
    End If
    End Sub

    However when the file is on the server, the workbook still closes.
    Following command yielded the following:

    Debug.Print ServerPath
    Debug.Print ThisWorkbook.Path
    Debug.Print ThisWorkbook.Path <> SeverPath

    P:\Documents and Settings\All Users\Documents
    P:\Documents and Settings\All Users\Documents
    True

    Why is If ThisWorkbook.Path <> SeverPath evaluating to true, eventhough
    both ServerPath and ThisWorkbook.Path is same?

    I am stumped. Any suggestions?

    TIA.


  2. #2
    Ardus Petus
    Guest

    Re: Verifying path fails for no apparent reason..Clueless

    Typo:
    > If ThisWorkbook.Path <> SeverPath Then


    should be:
    > If ThisWorkbook.Path <> ServerPath Then


    The error would be easier to find if you used Option Explicit

    HTH
    --
    AP

    <[email protected]> a écrit dans le message de news:
    [email protected]...
    > Hi
    >
    > What I want to do is to ensure that the workbook is opened only from
    > the designated folder, in this case it is a folder in a mapped network
    > drive P:\. The code works as intended if I try to open the workbook
    > from my C:\ drive, ie. the workbook closes showing the message box. The
    > code is:
    >
    > Const ServerPath As String = "P:\Documents and Settings\All
    > Users\Documents"
    >
    > Private Sub Workbook_Open()
    > If ThisWorkbook.Path <> SeverPath Then
    > MsgBox "You are not allowed to open the workbook from the
    > current location"
    > ThisWorkbook.Close
    > End If
    > End Sub
    >
    > However when the file is on the server, the workbook still closes.
    > Following command yielded the following:
    >
    > Debug.Print ServerPath
    > Debug.Print ThisWorkbook.Path
    > Debug.Print ThisWorkbook.Path <> SeverPath
    >
    > P:\Documents and Settings\All Users\Documents
    > P:\Documents and Settings\All Users\Documents
    > True
    >
    > Why is If ThisWorkbook.Path <> SeverPath evaluating to true, eventhough
    > both ServerPath and ThisWorkbook.Path is same?
    >
    > I am stumped. Any suggestions?
    >
    > TIA.
    >




  3. #3

    Re: Verifying path fails for no apparent reason..Clueless

    Bangs head on table.

    That was the only module I didnt have Option Explicit... :-(

    Thanks Ardus for pointing it out.

    Now there is another thing I just noticed. If I disable Macro on
    opening I can still view the Worksheet. I am wondering if there is a
    workaround to that...?

    Anyway thanks..




    Ardus Petus wrote:
    > Typo:
    > > If ThisWorkbook.Path <> SeverPath Then

    >
    > should be:
    > > If ThisWorkbook.Path <> ServerPath Then

    >
    > The error would be easier to find if you used Option Explicit
    >
    > HTH
    > --
    > AP
    >
    > <[email protected]> a =E9crit dans le message de news:
    > [email protected]...
    > > Hi
    > >
    > > What I want to do is to ensure that the workbook is opened only from
    > > the designated folder, in this case it is a folder in a mapped network
    > > drive P:\. The code works as intended if I try to open the workbook
    > > from my C:\ drive, ie. the workbook closes showing the message box. The
    > > code is:
    > >
    > > Const ServerPath As String =3D "P:\Documents and Settings\All
    > > Users\Documents"
    > >
    > > Private Sub Workbook_Open()
    > > If ThisWorkbook.Path <> SeverPath Then
    > > MsgBox "You are not allowed to open the workbook from the
    > > current location"
    > > ThisWorkbook.Close
    > > End If
    > > End Sub
    > >
    > > However when the file is on the server, the workbook still closes.
    > > Following command yielded the following:
    > >
    > > Debug.Print ServerPath
    > > Debug.Print ThisWorkbook.Path
    > > Debug.Print ThisWorkbook.Path <> SeverPath
    > >
    > > P:\Documents and Settings\All Users\Documents
    > > P:\Documents and Settings\All Users\Documents
    > > True
    > >
    > > Why is If ThisWorkbook.Path <> SeverPath evaluating to true, eventhough
    > > both ServerPath and ThisWorkbook.Path is same?
    > >
    > > I am stumped. Any suggestions?
    > >
    > > TIA.
    > >



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1