Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to unprotect table source workbook with password. 3

Status
Not open for further replies.

robles74

Programmer
Jan 31, 2014
16
MX
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:
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)
ThisWorkbook.RefreshAll

'
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("Registro").Select
Range("j10").Select
Sheets("Mach1").Visible = False
'
Sheets("Registro").Select
Range("j10").Select
'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
'UserForm2.Show
'Else
' 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")
'UserForm1.Show
'
'Bienvenida.Show
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.
 
Code:
Const DateEnd As Date = #11/15/2020#

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
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:
[tt]WBpath = "C:\\Users\Capacitacion\Documents\RootOfficeTemplates\Repositorio\Bases\MainDataSource.xlsx"
Set WB = Workbooks.Open(FileName:=WBpath, Password:=PW)[/tt]
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.


combo
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top