Option Explicit
Public dossier
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO, path As String, r As Long, x As Long, pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(Msg) Then
bInfo.lpszTitle = ""
Else
bInfo.lpszTitle = Msg
End If
bInfo.ulFlags = &H1
x = SHBrowseForFolder(bInfo)
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function
Sub File_Openen()
Dim fs, i, namefile, FileNumber, specfichier, nbfiles, r, Srep, folder, ct
dossier = GetDirectory("Choisit un dossier : ")
If dossier <> "" Then
Set fs = Application.FileSearch
With fs
.LookIn = dossier
.SearchSubFolders = True
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
nbfiles = .FoundFiles.Count
MsgBox "Il y a " & nbfiles & " Fichiers."
For i = 1 To nbfiles
specfichier = .FoundFiles(i)
Range("A" & i) = specfichier
Next i
End If
End With
End If
End Sub
Workbooks.Open Filename:=specfichier
Option Explicit
Public dossier
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO, path As String, r As Long, x As Long, pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(Msg) Then
bInfo.lpszTitle = ""
Else
bInfo.lpszTitle = Msg
End If
bInfo.ulFlags = &H1
x = SHBrowseForFolder(bInfo)
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function
Sub File_Openen()
Dim fs, i, namefile, FileNumber, specfichier, nbfiles, r, Srep, folder, ct
dossier = GetDirectory("Choisit un dossier : " )
If dossier <> "" Then
Set fs = Application.FileSearch
With fs
.LookIn = dossier
.SearchSubFolders = True
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
nbfiles = .FoundFiles.Count
MsgBox "Il y a " & nbfiles & " Fichiers."
For i = 1 To nbfiles
specfichier = .FoundFiles(i)
Workbooks.Open Filename:=specfichier
Next i
End If
End With
End If
End Sub
Sub ouvrir_fichiers()
Dim monfichier As String
monfichier = Dir("c:\test\*.*" )
Do While monfichier <> ""
Workbooks.Open monfichier
...
monfichier = Dir()
Loop
End Sub
' Code Visual Basic anglais
Sub ouvrir_fichiers()
'l'instruction ChDir permet de se positionner
'sur un répertoire précis
ChDir "C:\Documents and Settings\.....\Bureau\test\originaux"
monfichier = Dir("*.*")
While monfichier <> ""
Workbooks.Open monfichier
monfichier = Dir()
Range("A1").Select
Selection.EntireRow.Insert
Windows.Item(1).ActivateNext
Range("A1:G1").Select
Selection.Copy
Windows.Item(1).ActivateNext
ActiveSheet.Paste
Windows.Item(1).ActivateNext
Range("B2:G3").Select
Application.CutCopyMode = False
Selection.Copy
Windows.Item(1).ActivateNext
Range("B2").Select
ActiveSheet.Paste
Range("B2:G3").Select
Application.CutCopyMode = False
Application.CutCopyMode = False
Selection.DataSeries Rowcol:=xlRows, Type:=xlLinear, Date:=xlDay, Step _
:=1, Trend:=False
ActiveWindow.SmallScroll Down:=-3
Selection.AutoFill Destination:=Range("B2:G83"), Type:=xlFillDefault
Range("B2:G83").Select
Wend
'enquete_satisfaction()_
'
'
' Touche de raccourci du clavier: Ctrl+p
'
Range("A1").Select
Selection.EntireRow.Insert
Windows.Item(1).ActivateNext
Range("A1:G1").Select
Selection.Copy
Windows.Item(1).ActivateNext
ActiveSheet.Paste
Windows.Item(1).ActivateNext
Range("B2:G3").Select
Application.CutCopyMode = False
Selection.Copy
Windows.Item(1).ActivateNext
Range("B2").Select
ActiveSheet.Paste
Range("B2:G3").Select
Application.CutCopyMode = False
Application.CutCopyMode = False
Selection.DataSeries Rowcol:=xlRows, Type:=xlLinear, Date:=xlDay, Step _
:=1, Trend:=False
ActiveWindow.SmallScroll Down:=-3
Selection.AutoFill Destination:=Range("B2:G83"), Type:=xlFillDefault
Range("B2:G83").Select
End Sub
Sub ouvrir_modifier_et_fermer_fichiers()
Dim ClasseurDepart As Workbook
Dim ClasseurAModifier As Workbook
Set ClasseurDepart = Workbooks("nom du classeur de départ")
monfichier = Dir("C:\Documents and Settings\.....\Bureau\test\originaux\*.*")
Do While monfichier <> ""
Set ClasseurAModifier = Workbooks.Open(monfichier)
ClasseurAModifier.Worksheets(1).Rows(1).Insert
ClasseurDepart.Worksheets(1).Range("A1:G1").Copy ClasseurAModifier.Worksheets(1).Range("A1:G1")
ClasseurDepart.Worksheets(1).Range("B2:G3").Copy ClasseurAModifier.Worksheets(1).Range("B2:G3")
ClasseurAModifier.Worksheets(1).Range("B2:G3").DataSeries Rowcol:=xlRows, Type:=xlLinear, Date:=xlDay, Step:=1, Trend:=False
ClasseurAModifier.Worksheets(1).Range("B2:G3").AutoFill Destination:=Range("B2:G83"), Type:=xlFillDefault
ClasseurAModifier.Save
ClasseurAModifier.Close
monfichier = Dir()
Loop
Set ClasseurAModifier = Nothing
Set ClasseurDepart = Nothing
End Sub