VB ACCESS - Exportation d'une requête avec mot de passe

Fermé
steaker59 Messages postés 47 Date d'inscription jeudi 28 janvier 2010 Statut Membre Dernière intervention 22 décembre 2013 - 16 août 2013 à 15:05
f894009 Messages postés 17192 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 16 juin 2024 - 21 août 2013 à 09:49
Bonjour à tous,

J'exporte via un bouton d'un de mes formulaires une requête de ma base de données ACCESS.
J'aimerai que le fichier excel créé soit sécurisé par un mot de passe. Pourrais-je faire sa sous Access ?

Le code est correct vous le trouverez ci-dessous :


Private Sub Commande70_Click()

Dim a As String
b = Day(Date) & "_" & Month(Date) & "_" & Year(Date)
a = Application.CurrentProject.Path & "\export" & b & ".xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "Resultat", a
Dim xls As Excel.Application

On Error GoTo errHnd
Set xls = CreateObject("Excel.Application")
xls.Workbooks.Open Application.CurrentProject.Path & "\export" & b & ".xls"
xls.Visible = True
Exit Sub
errHnd:
MsgBox "Erreur N° " & Err.Number & vbLf & Err.Description, , Err.Source
End Sub


Merci infiniment pour votre aide !!
A voir également:

2 réponses

f894009 Messages postés 17192 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 16 juin 2024 1 708
17 août 2013 à 08:00
Bonjour,

Protection feuille:

Private Sub Commande70_Click()
    Dim a As String
    Dim xls As Excel.Application
    
    b = Day(Date) & "_" & Month(Date) & "_" & Year(Date)
    a = Application.CurrentProject.Path & "\export" & b & ".xls"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "Resultat", a
    
    On Error GoTo errHnd
    Set xls = CreateObject("Excel.Application")
    xls.Workbooks.Open Application.CurrentProject.Path & "\export" & b & ".xls"
    xls.Visible = True
    'Protection feuille: adaptez le nom de la feuille et le mot de passe
    xls.Workbooks(b & ".xls").Worksheets("Donnees").Protect Password:="Toto", DrawingObjects:=True, Contents:=True, Scenarios:=True
    xls.Workbooks(b & ".xls").Worksheets("donnees").EnableSelection = xlNoSelection
    
    Exit Sub
errHnd:
    MsgBox "Erreur N° " & Err.Number & vbLf & Err.Description, , Err.Source
End Sub
0
steaker59 Messages postés 47 Date d'inscription jeudi 28 janvier 2010 Statut Membre Dernière intervention 22 décembre 2013
Modifié par steaker59 le 20/08/2013 à 16:00
Merci beaucoup pour votre réactivité.
j'ai essayer votre code il me met que l'indice n'appartient pas à la sélection (erreur n°9)..
Le nom de la feuille à portant bien été remplacé
Pourriez-vous m'orienter ?
0
f894009 Messages postés 17192 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 16 juin 2024 1 708
20 août 2013 à 17:02
Bonjour,

Je vais faire des essais demain matin.


A+
0
f894009 Messages postés 17192 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 16 juin 2024 1 708
21 août 2013 à 09:49
Bonjour,

J'ai teste avec ce code (et une base personnelle), ca marche:

Private Sub Commande0_Click()
    Dim a As String
    Dim xls As Object
    
    b = Day(Date) & "_" & Month(Date) & "_" & Year(Date)
    a = Application.CurrentProject.Path & "\export" & b & ".xls"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "Resultat", a
   
    On Error GoTo errHnd
    Set xls = CreateObject("Excel.Application")
    xls.Workbooks.Open Application.CurrentProject.Path & "\export" & b & ".xls"
    xls.Visible = True
    'Protection feuille: adaptez le nom de la feuille et le mot de passe
    xls.Workbooks(b & ".xls").worksheets("Resultat").Protect Password:="Toto", DrawingObjects:=True, Contents:=True, Scenarios:=True
    xls.Workbooks(b & ".xls").worksheets("Resultat").EnableSelection = xlNoSelection
    xls.Quit
    Set xls = Nothing
    Exit Sub
errHnd:
    MsgBox "Erreur N° " & Err.Number & vbLf & Err.Description, , Err.Source
End Sub


A+
0