Vous êtes sur la page 1sur 3

honey script cu bentham

========================================= 1 nume fisier=========================


================================
Option Explicit
Sub GetFileNames()
Dim xRow As Long
Dim xDirect$, xFname$, InitialFoldr$
InitialFoldr$ = "G:\" '<<< Startup folder to begin searching from
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a folder to list Files from"
.InitialFileName = InitialFoldr$
.Show
If .SelectedItems.Count <> 0 Then
xDirect$ = .SelectedItems(1) & "\"
xFname$ = Dir(xDirect$, 7)
Do While xFname$ <> ""
ActiveCell.Offset(xRow) = xFname$
xRow = xRow + 1
xFname$ = Dir
Loop
End If
End With
End Sub

How to use:
This code is best placed in your Personal workbook, so it is always available fo
r you to use
Copy the above code
In Excel press Alt + F11 to enter the Visual Basic Editor
Press Ctrl + R to show the Project Explorer
Right-click on the Personal file on left (in bold).
Choose Insert -> Module
Paste code into the right hand pane
Press Ctrl + S to Save the Personal file
Press Alt + Q to close the VB Editor
Test the code:
With Excel open, open a New blank worksheet (if there's not one there already) b
y pressing Ctrl + N
Click on any cell on the blank worksheet
Press Alt + F8 to open the Macro dialogue box (or select Tools > Macro > Macros
from the top Excel toolbar)
Look for the macro named PERSONAL.XLS!GetFileNames and click on it (if you can't
see it on the list, ensure that the bottom selection box states 'All Open Workb
ooks')
Click RUN (or double-click the macro name from the list)
The FileDialog box should now appear - navigate to the folder that you want to f
ind the contents so the target Folder name is in the top 'Look in:' field
Click OK
The names of all of the contained Files (and their file type extensions e.g. '.x
ls', '.bmp')will be added to the worksheet as a vertical list, starting in the c
ell you selected

======================================================== 2 nume fisier2 ======


====================================================
nume fisier
sau varianta in care se poate alege si dupa extensie. la active cell offset dac
a se inverseaza 0 cu 1 afisare rand si nu coloana
Sub ListFiles()
F = Dir("C:\<ExcelFiles>\*.XLS")
Do While Len(F) > 0
ActiveCell.Formula = F
ActiveCell.Offset(1, 0).Select
F = Dir()
Loop
End Sub
======================================================= 3 nume fisier3==========
===================================
nume fisier si hyperlink automat
Sub
Dim
Dim
Dim
Dim

Example1()
objFSO As Object
objFolder As Object
objFile As Object
i As Integer

'Create an instance of the FileSystemObject


Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder("D:StuffBusinessTemp")
i = 1
Sheet3.Activate
'loops through each file in the directory
For Each objFile In objFolder.Files
'select cell
Sheet3.Range(Sheet3.Cells(i + 1, 1), Sheet3.Cells(i + 1, 1)).Select
'create hyperlink in selected cell
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
objFile.Path, _
TextToDisplay:=objFile.Name
i = i + 1
Next objFile
End Sub
========================================================= 4 notificare mail la
salvare ======================================================
mail notificare la schimbari. codul=>this workbook=>workbook=>before save adica
primul si ultimul rand din cod
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As B
oolean)
' Sheets("TargetSheet").Range("TargetRange").Select '#
ActiveWorkbook.EnvelopeVisible = True
With ActiveSheet.MailEnvelope
.Introduction = "Hello, ! - the workbook was saved by " & Environ("USERN
AME") & " at " & Format(Now(), "ddd dd mmm yy hh:mm")

.Item.To = "comanescu.raluca.m@gmail.com"
.Item.Subject = "Workbook Saved!"
' .Item.display
.Item.send
End With
End Sub
======================================================== 5 =====================
==================================================================
MsgBox

Vous aimerez peut-être aussi