Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to unprotect table source workbook with password.

How to unprotect table source workbook with password.

How to unprotect table source workbook with password.

Good afternoon to everyone.

I'm facing a trouble, when I try to refresh all via vba. I have a main table stored in a workbook, from this table depends several workbooks to update their table contents. When the "source" workbook remains without protection the ThisWorkbook.RefreshAll works fine, the trouble starts when I put a password to protect the source workbook, until now I try this:

CODE --> vba

Private Sub Workbook_Open()
Dim WB As Workbook
    Dim pw As String

Const DateEnd As Date = "11/15/2020"
If Date > DateEnd Then
MsgBox ("Este archivo no se puede ser usado sin licencia o autorizacion del autor")
ActiveWorkbook.Close SaveChanges:=False
End If
Set WB = "C:\\Users\Capacitacion\Documents\RootOfficeTemplates\Repositorio\Bases\MainDataSource.xlsx"
pw = "VLF800913"
WB.Unprotect (pw)

Sheets("Mach1").Visible = True
Sheets("Registro").Visible = xlSheetVeryHidden
Sheets("Empleados").Visible = xlSheetVeryHidden
Sheets("Diap1").Visible = xlSheetVeryHidden
Sheets("Diap2").Visible = xlSheetVeryHidden
Sheets("Diap3").Visible = xlSheetVeryHidden
Sheets("Diap4").Visible = xlSheetVeryHidden
Sheets("Diap5").Visible = xlSheetVeryHidden
Sheets("Diap6").Visible = xlSheetVeryHidden
Sheets("Diap7").Visible = xlSheetVeryHidden
Sheets("Diap8").Visible = xlSheetVeryHidden
Sheets("Diap9").Visible = xlSheetVeryHidden
Sheets("Diap10").Visible = xlSheetVeryHidden
Sheets("Evaluacion").Visible = xlSheetVeryHidden
Sheets("Registro").Visible = True
Sheets("Mach1").Visible = False
'If Range("b1").Value = "Bloqueado" Then
'Dim answer As Integer
'answer = MsgBox("Desea continuar? Le sera requerida una contraseƱa", vbYesNo + vbQuestion, "Desbloqueador de curso")
'If answer = vbYes Then
' ActiveWorkbook.Close SaveChanges:=False
'    End If
'End If

MsgBox ("Por favor digite su numero de empleado presione enter y enseguida presione al mismo tiempo Ctrl+Shift+V, esto para revisar si Usted ya ha iniciado alguno de los modulos y recuperar su informacion")
MsgBox ("Tenga en cuenta que al abrir el nuevo libro le sera requerido que haga lo mismo, por favor ignore la instruccion y seleccione directamente el formulario de seleccion de modulo")
End Sub 

Please forgive me due the simplicity in this code, but I'm not an expert in .vba

As soon the workbook starts I receive a compile error: Type mismatch

Any help with this issue, will be really appreciated, I know, maybe for giants like Skip this is a piece of cake, but I feel my self like a dog trying to catch his own tail.

Best regards and have a great day.

RE: How to unprotect table source workbook with password.

You are trying to assign a string to a date data type.

RE: How to unprotect table source workbook with password.


Const DateEnd As Date = #11/15/2020# 


glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: How to unprotect table source workbook with password.

The way you try to unprotect workbook can't work. You assign text to WB and try to unprotect text. If you plan to open password protected workbook:
WBpath = "C:\\Users\Capacitacion\Documents\RootOfficeTemplates\Repositorio\Bases\MainDataSource.xlsx"
Set WB = Workbooks.Open(FileName:=WBpath, Password:=PW)

If you need to update links from password protected workbook without opening it, there is no VBA interface for this, only SendKeys can be used to pass the password.


RE: How to unprotect table source workbook with password.

Good afternoon.

Skip and mintjulep thank you for your advice regarding the way to assign the date, but just as an observation, this way to assign the date works fine for me, I'll make the change to do the thing in the correct way.

Combo, it works, I'll continue with the development of this sub to perform the task.

Thanks a lot to everyone.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close