J
James
Hi Everyone,
I'm very new to programming with word. I know a little about vb when working
with excel. I have a problem....
From a word document, I need to open an Excel file, activate the "data" page
(which is xlveryhidden), Search through the data page for a 5 digit number,
once the number is found, I need to access the next few cells {ie.
offset(0,1) & offset(0,2)} then use that info to compare against some text a
user input into a userform. I have the code written in excel and it works
fine, I just need it to be converted over so it works for word documents.
here is the excel version. thanks in advance
Function LoginCheck() As Boolean
On Error GoTo LoginCheck_Error
Dim admin As Boolean
Dim pass As String
Dim dept As String
Dim dbadge As String
Dim sheetpass As String
Workbooks.Open dbpath 'dbpath is a constant
Windows("Stamp Spreadsheet.xls").Activate
ActiveWorkbook.Sheets("Data").Activate
sheetpass = ActiveWorkbook.ActiveSheet.Cells(3, 10).Value
ActiveWorkbook.ActiveSheet.Unprotect (sheetpass)
dbadge = UserForm1.TextBox1
j = Sheets("Data").Cells(Rows.count, "A").End(xlUp).Row
n = 1
While n <= j
If InStr(Sheets("Data").Cells(n, 3).Value, dbadge) > 0 Then
pass = Cells(n, 5).Value
dept = Cells(n, 4).Value
If Cells(n, 6).Value <> "" Then
admin = True
Else
admin = False
End If
ActiveWorkbook.ActiveSheet.Protect (sheetpass)
ActiveWorkbook.Close SaveChanges:=False
If pass <> strPasswb Then
MsgBox "Incorrect Login. Try Again", vbOKOnly
status = False
Exit Function
End If
If pass = strPasswb Then
If Not (IsNull(admin)) Then
strUserAccess = admin
Else
strUserAccess = ""
End If
If dept = "379" Then
status = True
ElseIf dept = "378" Then
status = True
ElseIf dept = "405" Then
status = True
Else
MsgBox ("YOU ARE NOT AUTHORIZED TO STAMP THIS FORM.")
status = False
Exit Function
End If
LoginCheck = True
Exit Function
Else
LoginCheck = False
MsgBox ("Incorrect Password. Try again.")
Exit Function
End If
ElseIf n < j Then
n = n + 1
ElseIf n >= j Then
MsgBox "You must create an account to stamp"
ActiveWorkbook.ActiveSheet.Protect ("123")
ActiveWorkbook.Close SaveChanges:=False
LoginCheck = False
status = False
Exit Function
End If
Wend
I'm very new to programming with word. I know a little about vb when working
with excel. I have a problem....
From a word document, I need to open an Excel file, activate the "data" page
(which is xlveryhidden), Search through the data page for a 5 digit number,
once the number is found, I need to access the next few cells {ie.
offset(0,1) & offset(0,2)} then use that info to compare against some text a
user input into a userform. I have the code written in excel and it works
fine, I just need it to be converted over so it works for word documents.
here is the excel version. thanks in advance
Function LoginCheck() As Boolean
On Error GoTo LoginCheck_Error
Dim admin As Boolean
Dim pass As String
Dim dept As String
Dim dbadge As String
Dim sheetpass As String
Workbooks.Open dbpath 'dbpath is a constant
Windows("Stamp Spreadsheet.xls").Activate
ActiveWorkbook.Sheets("Data").Activate
sheetpass = ActiveWorkbook.ActiveSheet.Cells(3, 10).Value
ActiveWorkbook.ActiveSheet.Unprotect (sheetpass)
dbadge = UserForm1.TextBox1
j = Sheets("Data").Cells(Rows.count, "A").End(xlUp).Row
n = 1
While n <= j
If InStr(Sheets("Data").Cells(n, 3).Value, dbadge) > 0 Then
pass = Cells(n, 5).Value
dept = Cells(n, 4).Value
If Cells(n, 6).Value <> "" Then
admin = True
Else
admin = False
End If
ActiveWorkbook.ActiveSheet.Protect (sheetpass)
ActiveWorkbook.Close SaveChanges:=False
If pass <> strPasswb Then
MsgBox "Incorrect Login. Try Again", vbOKOnly
status = False
Exit Function
End If
If pass = strPasswb Then
If Not (IsNull(admin)) Then
strUserAccess = admin
Else
strUserAccess = ""
End If
If dept = "379" Then
status = True
ElseIf dept = "378" Then
status = True
ElseIf dept = "405" Then
status = True
Else
MsgBox ("YOU ARE NOT AUTHORIZED TO STAMP THIS FORM.")
status = False
Exit Function
End If
LoginCheck = True
Exit Function
Else
LoginCheck = False
MsgBox ("Incorrect Password. Try again.")
Exit Function
End If
ElseIf n < j Then
n = n + 1
ElseIf n >= j Then
MsgBox "You must create an account to stamp"
ActiveWorkbook.ActiveSheet.Protect ("123")
ActiveWorkbook.Close SaveChanges:=False
LoginCheck = False
status = False
Exit Function
End If
Wend