LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Help with macro used to open files - unpredictable results!

Hello

I have been trying to use a macro to allow users to open their own
personalised logs which are password protected. Users click on a button and
then the macro asks for their User ID. After entering their User ID the macro
then asks for their password. If the password is correct, the macro then
opens that user's individual file.

For this to work, the macro reads data from a hidden worksheet. This hidden
worksheet has data in three columns: A, B and C. The first column contains
the User ID, the second column contains passwords, and the third column
contains the full file path.

The problem I have is this: The hidden worksheet has details for 64 users,
but the macro only recognises 14 of these users. As a result, these users
cannot open their files. I am at a total loss to explain why. It makes no
difference what order the users are listed within the hidden worksheet, and
there is no obvious pattern to either those users who are recognised or those
who aren't. I really am at a total loss.

Any help would be greatly appreciated as I need this for work on Monday.

Thanks.


The macro code is below:

Sub FindStaff()
Dim FoundCell As Range
Dim ws1 As Worksheet
Dim Search As Variant
Dim Passwrd As Variant
Dim MyFile As String
Dim MyTitle As String
Dim OpenWB As Workbook

Set ws1 = Worksheets("Users") '<< change as required

MyTitle = "Open My WorkBook"

startsearch:
Search = Application.InputBox(prompt:="User ID",
Title:=MyTitle, Type:=2)


If Search = False Then Exit Sub

'search for staff number
Set FoundCell = ws1.Columns("A").Find _
(Search, LookIn:=xlValues, _
LookAt:=xlWhole)

If FoundCell Is Nothing = False Then

i = 1
enterpassword:
Passwrd = Application.InputBox(prompt:="Enter Password" & Chr(10) &
"Attempt " & i, Title:=MyTitle2, Type:=2)

If Passwrd = False Then Exit Sub

'check password value in Col B
If FoundCell.Offset(0, 1).Value = CStr(Passwrd) Then

'get file name & path from Col C
MyFile = FoundCell.Offset(0, 2).Value

On Error GoTo myerror
Set OpenWB = Workbooks.Open(MyFile, Password:=Passwrd)

'do stuff here

Else

msg = MsgBox("Password Not Valid", vbInformation, MyTitle)

i = i + 1

If i 3 Then

Exit Sub

Else

GoTo enterpassword

End If

End If

Else

msg = MsgBox("Value " & Search & " Not Found", vbInformation, MyTitle)

GoTo startsearch

End If

myerror:
If Err 0 Then

MsgBox (Error(Err))
Err.Clear

End If

End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Files with Macro or switch windows with macro Noe Excel Programming 6 September 30th 09 04:06 PM
Unpredictable results with Macro and VBA joesf16 Excel Programming 1 September 7th 07 10:06 AM
macro to open in all files Tiya Excel Programming 1 July 11th 06 05:57 PM
Macro Open Files MSHO Excel Programming 2 January 11th 06 11:06 PM
Macro to open *.dat files and save as .txt (comma delimited text files) [email protected] Excel Programming 2 November 30th 05 05:50 AM


All times are GMT +1. The time now is 11:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"