Results 1 to 5 of 5

Thread: Issue with password window

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    2

    Issue with password window

    I have an issue. My code opens protected workbook in background - and it works fine, no issue, but when workbook is already open by other user, password window pops up - how to change that so user won't be able to see that password window? I add on error goto errhandler which contains that workbook is already open - it works fine when workbook is not protected, but with protected one this password window pops up.

    Long story short:
    when app opens a password protected workbook code works fine, but when app opens a password protected workbook that another user has open, it asks for the password?

    Thank You in advance

    Code:
    on error goto errhan
    Workbooks.Open Filename:= "C:\johndoe.xls", Password:="Password"
    exit sub
    
    errhan
    messagebox.show("File is already open")
    Any suggestions?

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Issue with password window

    I've modified your post to include [code][/code] BB tags. In the future, please use them as it keeps your code formatted. I have a link on how to use the code formatting tags in my signature.

    Also, on error goto is legacy syntax. Could you verify the specific language you're using (VB6, VBA for Excel, VB.NET, etc.)?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Issue with password window

    Quote Originally Posted by dday9 View Post
    Also, on error goto is legacy syntax. Could you verify the specific language you're using (VB6, VBA for Excel, VB.NET, etc.)?
    Definitely not VB.NET, as Workbooks.Open has no parentheses. Almost certainly VBA, given that Workbooks is unqualified.

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2020
    Posts
    2

    Re: Issue with password window

    I'm using VB.Net with Imports Excel = Microsoft.Office.Interop.Excel
    Code:
    Dim Epath As String = "C:\Users\Bartek\Desktop\New folder\data.xlsx"
    		Dim excel As Microsoft.Office.Interop.Excel.Application
    		excel = New Microsoft.Office.Interop.Excel.Application
    		Dim wBook As Microsoft.Office.Interop.Excel.Workbook
    		Dim ws As Microsoft.Office.Interop.Excel.Worksheet
    		Dim lr As Long, excelRow As Long
    		On Error GoTo APPERR
    		excel.Visible = False
    		excel.UserControl = False
    		wBook = excel.Workbooks.Open(Epath, Password:="Banik123", UpdateLinks:=False)
    		ws = excel.ActiveSheet
    		lr = ws.Range("A" & ws.Rows.Count).End(XlDirection.xlUp).Row + 1
    		excelRow = lr
    		If wBook.ReadOnly = True Then
    			MessageBox.Show("Data base is busy, please try again later")
    			wBook.Close()
    			releaseObject(excel)
    			releaseObject(wBook)
    			releaseObject(ws)
    			Exit Sub
    		End If

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Issue with password window

    Quote Originally Posted by ave470 View Post
    I'm using VB.Net
    And yet the code in post #4 is quite different to the code in post #1. If you want help with code then it's a good idea to post the code you want help with. Mind you, MessageBox.Show is specifically VB.NET so that original code would not work anywhere.

Posting Permissions

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



Click Here to Expand Forum to Full Width