aide: données de connexion...

G

gravelines

Guest
salut,

j'aurais besoin d'aide, sous Excel, en version réseau sous NT4, comment automatiser le sauvedarde d'un fichier, lorsqu'il est modifié.... en nommant la sauvegarde de la sorte: [quadrigramme_date_heure_filename].xls


je voudrais en plus que cette archive ne soit pas placée dans le même rep que le fichier d'origine, et que cette archive soit dispo en lecture seule...

Suis-je clair?

tout celà sous Excel 2000.

Merci à tous.


Greg.
 
@

@+Thierry

Guest
Salut Gravelines,

Si j'ai bien compris... unee macro comme çà devrait faire en partie (ou tout ?) ce que tu veux...

Sub Sauvegarde()
DateHeure = Format(Now, "DD MM YYYY HH SS")
Nom = "Quadrigramme " & DateHeure & ThisWorkbook.Name & ".xls"
ActiveWorkbook.SaveAs "C:\mes documents\Archives\" & Nom, , , , True
End Sub

NB il faut que tu aies un répertoire "Mes Documents" puis un Sous-répertoire "Archives" pour éviter une erreur.

Bon App
@+Thierry
 
G

gravelines

Guest
Salut Thierry,

merci, on s'approche du but, mais comment aller chercher automatiquement le trigramme ou quadrigramme de celui qui est connecté??? (les postes sont en NT4, donc à l'ouverture d'une cession, saisie d'un trigramme ou quadrigramme [preg pour grégory peere par ex], et mot de passe -----> celà va définir les droits sur les fichiers sus-cités [pas d'accès, accès en lecture seule, ou en lecture/écriture]

Faudra-t-il faire appel aux API?

A noter que dans les propriétés du doc ouvert (de la feuille en fait!), mon trigramme apparait... mais comment récupérer cette donnée? Et puis si cette donnée est rapatriée à l'ouverture de la feuille, il suffirait de changer volontairement la donnée pour brouiller les pistes...

Je ne vois que les API pour le moment, mais là...

Merci encore si qqun voit la soluce.

Greg.
 
G

gravelines

Guest
In the previous tutorial we have found out how to get an IP address of the remote host by its name. We have used the gethostbyname function to achieve that and we can use that function in order to get an IP address of the local system as well. But how to get a host name of the local system? The Winsock API provides us with the function which just does what we need - gethostname. This function retrieves the local host name and we can use that name in order to get all the IP addresses of the local system.

Declare Function gethostname Lib "ws2_32.dll" (ByVal host_name As String, _
ByVal namelen As Long) As Long

The function receives two arguments. The first argument is just a string buffer in which the function puts retrieved host name, and the second one is a length of that buffer. The typical usage of the function is shown below:

...
Dim strHostName As String * 256 'buffer
Dim lngRetVal As Long 'returned value
...
lngRetVal = gethostname(strHostName, 256)
...


If no error occurs, the function returns zero. Otherwise, it returns SOCKET_ERROR and a specific error code can be retrieved with Err.LastDllError.

...
Dim strHostName As String * 256 'buffer
Dim lngRetVal As Long 'returned value
...
lngRetVal = gethostname(strHostName, 256)

If lngRetVal = SOCKET_ERROR Then
'
ShowErrorMsg (Err.LastDllError)
'
Else
'
Debug.Print "Local host name: " & strHostName
'
End If
...


Possible error codes are in the table:

Error code Meaning
WSAEFAULT The name parameter is not a valid part of the user address space, or the buffer size specified by namelen parameter is too small to hold the complete host name.
WSANOTINITIALISED A successful WSAStartup call must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.

Creating sample application

We don't need much to create the sample. Open the project that we worked on in the previous tutorial, and just add the highlighted code into the cmdGet_Click event procedure:

Private Sub cmdGet_Click()
'----------------------------------------------------
'pointer to HOSTENT structure returned by
'the gethostbyname function
Dim lngPtrToHOSTENT As Long
'
'structure which stores all the host info
Dim udtHostent As HOSTENT
'
'pointer to the IP address' list
Dim lngPtrToIP As Long
'
'byte array that contains elemets of an IP address
Dim arrIpAddress() As Byte
'
'result IP address string to add into the ListBox
Dim strIpAddress As String
'
'buffer string to receive the local system host name
Dim strHostName As String * 256
'
'value returned by the gethostname function
Dim lngRetVal As Long
'----------------------------------------------------
'
'Clear the ListBox control
List1.Clear
'
'Get the local host name
lngRetVal = gethostname(strHostName, 256)
'
If lngRetVal = SOCKET_ERROR Then
ShowErrorMsg (Err.LastDllError)
Exit Sub
End If
'
Text1.Text = Left(strHostName, InStr(1, strHostName, Chr(0)) - 1)
'
'Call the gethostbyname Winsock API function
'to get pointer to the HOSTENT structure
lngPtrToHOSTENT = GetHostByName(Trim$(Text1.Text))
'
'Check the lngPtrToHOSTENT value
If lngPtrToHOSTENT = 0 Then
'
'If the gethostbyname function has returned 0
'the function execution is failed. To get
'error description call the ShowErrorMsg
'subroutine
'
ShowErrorMsg (Err.LastDllError)
'
Else
'
'The gethostbyname function has found the address
'
'Copy retrieved data to udtHostent structure
RtlMoveMemory udtHostent, lngPtrToHOSTENT, LenB(udtHostent)
'
'Now udtHostent.hAddrList member contains
'an array of IP addresses
'
'Get a pointer to the first address
RtlMoveMemory lngPtrToIP, udtHostent.hAddrList, 4
'
Do Until lngPtrToIP = 0
'
'Prepare the array to receive IP address values
ReDim arrIpAddress(1 To udtHostent.hLength)
'
'move IP address values to the array
RtlMoveMemory arrIpAddress(1), lngPtrToIP, udtHostent.hLength
'
'build string with IP address
For i = 1 To udtHostent.hLength
strIpAddress = strIpAddress & arrIpAddress(i) & "."
Next
'
'remove the last dot symbol
strIpAddress = Left$(strIpAddress, Len(strIpAddress) - 1)
'
'Add IP address to the listbox
List1.AddItem strIpAddress
'
'Clear the buffer
strIpAddress = ""
'
'Get pointer to the next address
udtHostent.hAddrList = udtHostent.hAddrList + LenB(udtHostent.hAddrList)
RtlMoveMemory lngPtrToIP, udtHostent.hAddrList, 4
'
Loop
'
End If
'
End Sub

That's it. In the next part we'll learn how to get a host name by its IP address.



--------------------------------------------------------------------------------
 

Pièces jointes

  • GetLocalHost.zip
    4.5 KB · Affichages: 35
G

gravelines

Guest
ya ça aussi... mais how to?

There are several cases, when you want to know a user's login name, i.e. when you want to restrict the use of an application or when you want to generate a private filename for a user.

The solution differs according to the operating system used:

Windows NT: Use the %SYSGET macro:
%LET username=%SYSGET(USERNAME);

de (from) http://www.pwcons.com/Tips/af/modulen.html#Username
 
@

@+Thierry

Guest
Morning Gravelines

This is not an US or UK forum !!! lol....
But u can have an easy solution with the following code... using a standard API

Quand à ton histoire de "Trigramme ou de Quadrigramme" de réseau NT ou 2000 ceci dépend du bon vouloir de ton NetWork Admin quand il créé les Users. La fonction "GetUserName" ci-dessous récupérera exactement le Log-In du user en cours d'utilisation (que ce soit Preg ou Gregory Peere).

Pour ce qui est des propriétés du doc ouvert, ce nom d'utilisateur (auteur) dans propriété dépend d'Excel (menu / Outil / Option / Géneral => Nom d'Utilisateur) qui bien sûr peut-être changé à volonté. et que l'on peut récupérer sans API mais par la simple propriété "UserName" comme dans l'exemple ci-dessous :

Sub NomUtilisateur()
MsgBox "L'Utilisateur enregistré dans Excel est " & Application.UserName
End Sub

Le nom d'utilisateur qui apparait n'a strictement rien à voir avec le Log-In qui sera donc récupéré par la fonction "GetUserName" par cette macro que j'ai mise à jour avec les éléments que tu as décrits jusqu'à présent...

Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long
Sub Sauvegarde()

Dim lpBuff As String * 25
Dim ret As Long
Dim UserName As String
Dim DateHeure As String
Dim Nom As String
Dim Chemin As String

ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)

Chemin = "C:\mes documents\" 'changer le path (ou le récupérer) ici
DateHeure = Format(Now, "DD MM YYYY HH MM SS")
Nom = UserName & "-" & DateHeure & "-" & ThisWorkbook.Name & ".xls"
ActiveWorkbook.SaveAs Chemin & Nom, , , , True

End Sub

Voilà... Ceci devrait faire ton affaire... Par contre dans les codes que tu as collé ci-dessus et que je n'ai pas essayé d'interpréter... on parle de récupérer l'IP, çà je ne m'en suis pas occupé vu que ce n'est pas ce que tu as demandé.

Have a nice Sunday, the last of the year !!! so best wishes for the coming year
Bon Dimanche aux Francophones !!!
@+Thierry
 
G

gravelines

Guest
Merci à toi, Thierry.

je vais expérimenter ça au boulot, dès que j'aurais repris!!! (voir grégory P pour de plus amples explications... 3/8)

Car chez moi c'est w98 qui tourne.

Merci encore Thierry.

Et bon Dimanche.


(http://www.excel-downloads.com/html/French/forum/read.php?f=1&i=11324&t=10919 le message n'avait interpellé personne)
 
@

@+Thierry

Guest
Tu dois pouvoir tester sous Win 98... Même si tu n'es pas en réseau... GetUserName devrait retourner soit le nom de l'ordi si tu nas pas paramétré plusieurs utilisateurs je pense (Win 98 j'ai plus touché depuis 4 ans au moins ....)

Pour ton Post 10919... Euf !! oui je pense l'avoir survolé et rien capté !! lol
en général je post toujours un message pour le dire, là j'ai dû zapé, c'est vrai que l'on ne peut tout voir... sorry

@+Thierry
 
G

gravelines

Guest
Salut Ter tous,

milles mercisssss Thierry, ta macro fonctionne à merveille chez moi sous 98, mon portable est en réseau, et la routine retourne bien le trigramme de connexion. Je vais juste changer l'ordre du "Nom" pour mettre la date en premier, de manière à lire directement l'historique des sauvegardes.

Merci encore.

une question encore;

peut-on faire un 'différence' entre deux feuilles de calcul? (ou tracer, faire ressortir un évolution, un changement?) ---> l'idée, c'est que celui qui modifie le planing, engendre une sauvegarde automatique, pas avec le planing complet, mais juste avec les évolutions qu'il a apporté (apports ou retraits)...

sais pas si suis clair?
j'ai joint un exemple de feuille de planing, le semestre2. ---> ha non, trop grosse!
 

Discussions similaires

Statistiques des forums

Discussions
312 165
Messages
2 085 880
Membres
103 009
dernier inscrit
dede972