Open Excel Workbook & Find Number

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
 
J

James

Thanks for the info. I should be able to make something work from that.
One other question though. It says add a reference to Excel. I added
"Microsoft Excel 9.0 Object Library" is this the correct reference to add
for this? im not too familiar with these reference n such. Thanks again so
much for the info
 
D

Doug Robbins - Word MVP

If that is the version of the Object Library that is on your system, it
should be OK (on that system)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top