Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post

    expected expression error (Excel 2003)

    Hi

    I get an expected expression error, I've tried help but cannot understand how to correct it.

    Dim bOK2Use As Boolean
    Private Sub btnOK_Click()
    Dim bError As Boolean
    Dim sSName As String
    Dim p As DocumentProperty
    Dim bSetlt As Boolean
    bOK2Use = False
    bError = True
    If Len(txtUser.Text) > 0 And Len(txtpass.Text) > 0 Then
    bError = False
    Select Case txtUser.Text
    Case "userl"
    sSName = "ulsheet"
    If txtpass.Text <> "ulpass" Then bError = True
    Case "user2"
    sSName = "u2sheet"
    If txtpass.Text <> "u2pass" Then bError = True
    Case Else
    bError = True
    End Select
    End If
    If bError Then
    MsgBox "Invalid User Name or Password"
    Else
    'Set document property
    bSetlt = False
    For Each p In ActiveWorkbookCustomDocumentProperties
    If p.Name = "auth" Then
    p.Value = sSName
    bSetlt = True
    Exit For
    End If
    Nextp
    If Not bSetlt Then
    Active Workbook.CustomDocumentProperties.Add_
    Name:="auth",Linkto Content:=False _ <------ I get a compile error here,expected expression
    Type:=msoPropertyType5tring, Value:=sSName
    End If
    Sheets(sSName).Visible = True
    Sheets(sSName).Unprotect (txtpass.Text)
    Sheets(sSName).Activate
    bOK2Use = True
    Unload UserForml
    End If
    End Sub
    Private Sub UserForm_Terminate()
    If Not bOK2Use Then
    ActiveWorkbook.Close (False)
    End If
    End Sub

    Many Thanks
    Braddy
    If you are a fool at forty, you will always be a fool

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: expected expression error (Excel 2003)

    Expected errors aren't so bad, it's the unexpected ones that get you! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    There are oodles of typos in the code. Change
    <code>
    For Each p In ActiveWorkbookCustomDocumentProperties
    </code>
    to
    <code>
    For Each p In ActiveWorkbook.CustomDocumentProperties
    </code>
    Change
    <code>
    Nextp
    </code>
    to
    <code>
    Next p
    </code>
    Change
    <code>
    Active Workbook.CustomDocumentProperties.Add_
    Name:="auth",Linkto Content:=False _
    Type:=msoPropertyType5tring, Value:=sSName
    End If
    </code>
    to
    <code>
    ActiveWorkbook.CustomDocumentProperties.Add _
    Name:="auth", LinkToContent:=False, _
    Type:=msoPropertyTypeString, Value:=sSName
    </code>
    (no space in ActiveWorkbook and in LinkToContents, space between Add and _, msoPropertyTypeString instead of msoPropertyType5tring)

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    Northampton, Northamptonshire, England
    Posts
    1,951
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: expected expression error (Excel 2003)

    Hi Hans

    Glad I could make you chuckle, it's probably obvious to you that I scanned the text into a document and then tried to make sense of it.

    Many thanks

    Braddy
    If you are a fool at forty, you will always be a fool

Posting Permissions

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