Click here to Skip to main content
15,914,780 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Run-time error Pin
MsmVc16-May-10 21:34
MsmVc16-May-10 21:34 
GeneralRe: Run-time error Pin
DaveAuld16-May-10 23:01
professionalDaveAuld16-May-10 23:01 
GeneralRe: Run-time error Pin
MsmVc16-May-10 23:06
MsmVc16-May-10 23:06 
GeneralRe: Run-time error Pin
DaveAuld16-May-10 23:55
professionalDaveAuld16-May-10 23:55 
GeneralRe: Run-time error Pin
MsmVc16-May-10 23:57
MsmVc16-May-10 23:57 
GeneralRe: Run-time error Pin
DaveAuld16-May-10 23:59
professionalDaveAuld16-May-10 23:59 
GeneralRe: Run-time error Pin
MsmVc17-May-10 0:10
MsmVc17-May-10 0:10 
GeneralRe: Run-time error [modified] Pin
DaveAuld17-May-10 0:43
professionalDaveAuld17-May-10 0:43 
[Edit2: Original did work, sorry]




VB
Sub Button1_Click()

Dim xl As New Excel.Application
Dim xlsheet As Excel.Worksheet
Dim xlwbook As Excel.Workbook

Dim ExcelFile As String
Dim ExcelPassword As String
Dim i As Integer

'Set Filename
ExcelFile = "C:\Users\Dave Auld\Desktop\password_test.xlsx"

'Create Excel Application
Set xl = CreateObject("Excel.application")
xl.Visible = False

On Error Resume Next

For i = 1 To 6
 ExcelPassword = "ABC" + CStr(i)
 
 Set xlBook = xl.Workbooks.Open(Filename:=ExcelFile, Password:=ExcelPassword)

    If Err.Number > 0 Then
        MsgBox "Error: " + Err.Number + ": " + Err.Description, , "Error"
        'Reset the error for next loop
        Err = 0
    Else
        'No Error - File Opened okay
        MsgBox "File Opened with Password " + ExcelPassword
        'Stop Seraching
        Exit For
    End If
 Next i
 'Quit Excel
    xl.Quit

End Sub

Dave

Don't forget to rate messages!
Find Me On: Web|Facebook|Twitter|LinkedIn
Waving? dave.m.auld[at]googlewave.com


modified on Monday, May 17, 2010 6:51 AM

GeneralRe: Run-time error Pin
MsmVc18-May-10 22:15
MsmVc18-May-10 22:15 
GeneralRe: Run-time error Pin
DaveAuld18-May-10 22:54
professionalDaveAuld18-May-10 22:54 
AnswerRe: Run-time error Pin
Sonhospa16-May-10 23:57
Sonhospa16-May-10 23:57 
AnswerRe: Run-time error Pin
William Winner17-May-10 8:10
William Winner17-May-10 8:10 
GeneralRe: Run-time error Pin
DaveAuld18-May-10 22:54
professionalDaveAuld18-May-10 22:54 
GeneralRe: Run-time error Pin
William Winner19-May-10 4:45
William Winner19-May-10 4:45 
GeneralRe: Run-time error Pin
DaveAuld19-May-10 4:48
professionalDaveAuld19-May-10 4:48 
QuestionVB.Net Firebird ADO Pin
FrankPacher16-May-10 12:23
FrankPacher16-May-10 12:23 
AnswerRe: VB.Net Firebird ADO Pin
Dalek Dave16-May-10 13:07
professionalDalek Dave16-May-10 13:07 
AnswerRe: VB.Net Firebird ADO Pin
Simon_Whale16-May-10 22:13
Simon_Whale16-May-10 22:13 
Questionhow to find text in excel with vb.net? Pin
sanyexian15-May-10 21:42
sanyexian15-May-10 21:42 
AnswerRe: how to find text in excel with vb.net? Pin
dan!sh 16-May-10 0:24
professional dan!sh 16-May-10 0:24 
GeneralRe: how to find text in excel with vb.net? Pin
Dalek Dave16-May-10 1:42
professionalDalek Dave16-May-10 1:42 
Questionshape drawing and coordinations Pin
tuolesi15-May-10 5:12
tuolesi15-May-10 5:12 
AnswerRe: shape drawing and coordinations Pin
DaveAuld15-May-10 5:31
professionalDaveAuld15-May-10 5:31 
GeneralRe: shape drawing and coordinations Pin
tuolesi15-May-10 6:37
tuolesi15-May-10 6:37 
GeneralRe: shape drawing and coordinations Pin
DaveAuld15-May-10 6:42
professionalDaveAuld15-May-10 6:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.