![]() |
| Le forum de référence en programmation et développement. Articles, cours et tutoriels du débutant au chef de projet et DBA confirmé. | |||||||
|
|||||||
![]() |
|
|
Outils de la discussion |
|
|
#1 (permalink) | |
![]() Date d'inscription: février 2005
Localisation: Une petite rue qui "avait" un merle
Messages: 11 637
|
Citation:
Développé sous PowerPoint 97, La fonction InstrRev97 remplace la fonction du même nom des versions ultérieures Me facilite la récupérération du nom de fichier. Fonction Lister() : Dans cette fonction, la déclaration de fs en variant m'évite de valider la référence "Microsoft scripting runtime" dans l'éditeur VBA. Si cela pose un pb, la valider. Sub Redimensionnement() : Adapter les lignes de cette procédure à la taille de la diapo en mode création (dépend ici aussi de la définition de l'écran) Exécution : Adapter 'Chemin' et 'NewPath' dans la procédure "Appel()" et l'exécuter. Le code : Code :
Option Explicit Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _ ByVal dwFlags As Long, ByVal dwExtraInfo As Long) Public XlApp Public XlCL1 Public XLFL1 Public nb As Integer Code :
Sub Appel() Dim Chemin As String, NewPath As String Set XlApp = Excel.Application Set XlCL1 = XlApp.Workbooks.Add XlApp.Visible = False XlApp.DisplayAlerts = False XlApp.ScreenUpdating = False Chemin = "D:\Album photos\2002-2005 - Verlaine" 'Chemin des fichiers à ouvrir NewPath = "D:\VERLEINE\" 'chemin des copies réduites On Error Resume Next ChDir NewPath If Err <> 0 Then MsgBox "Créer le répertoire " & NewPath & " avant d'exécuter ce programme", 0, "" Exit Sub End If On Error GoTo 0 Lister Chemin, NewPath XlCL1.Close False XlApp.Quit Set XLFL1 = Nothing Set XlCL1 = Nothing Set XlApp = Nothing End Sub Code :
Public Function Lister(Chemin As String, NewPath As String) Dim fs, Rep As Variant, NewRep As String, NomFich As String, Envers As String Set fs = CreateObject("Scripting.FileSystemObject") Lister = fs.GetFolder(Chemin).Files.Count NomFich = Dir(Chemin & "\*.jpg") Do While NomFich <> "" CopieEcran_En_jpg NewPath, Chemin & "\", NomFich NomFich = Dir() Loop 'Pour chaque sous-répertoire, appel récursif de Lister For Each Rep In fs.GetFolder(Chemin).SubFolders Envers = InstrRev97(Rep.Path) NewPath = "D:\VERLEINE\" & Right(Rep.Path, InStr(Envers, "\") - 1) & "\" On Error Resume Next MkDir NewPath On Error GoTo 0 NewRep = Lister(Rep.Path, NewPath) Next Rep End Function Code :
Function InstrRev97(Envers As String) As String Dim i As Integer For i = Len(Envers) To 1 Step -1 InstrRev97 = InstrRev97 & Mid(Envers, i, 1) Next End Function Code :
'Valider Microsoft Excel 10.0 Object library Sub CopieEcran_En_jpg(NewPath As String, Chemin As String, NomFich As String) Dim Limage As String Dim Shp DoEvents Set XLFL1 = XlCL1.Sheets.Add ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:=Chemin & NomFich, LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=-1091, Top:=-701).Select DoEvents Redimensionnement 'procédure tenant compte du mode de l'image (Portrait/Paysage) 'Lance la présentation ActivePresentation.SlideShowSettings.Run 'Copie d'écran keybd_event vbKeySnapshot, 1, 0&, 0& DoEvents 'Interrompt la présentation dans PowerPoint SlideShowWindows(Index:=1).View.Exit 'Dans EXCEL 'Collage de l'image afin d'en connaître la dimension XLFL1.Paste DoEvents Set Shp = XLFL1.Shapes(XLFL1.Shapes.Count) Limage = NewPath & NomFich Dim Gr With XLFL1.ChartObjects.Add(0, 0, Shp.Width, Shp.Height).Chart Set Gr = XLFL1.Shapes(XLFL1.Shapes.Count) .Paste DoEvents With XLFL1.ChartObjects(1).Border .ColorIndex = 1 .Weight = 1 .LineStyle = 1 End With With XLFL1.ChartObjects(1).Interior .ColorIndex = 1 .PatternColorIndex = 2 .Pattern = 1 End With DoEvents .Export Limage, "JPG" DoEvents Set Gr = Nothing End With ActivePresentation.Slides(1).Shapes(1).Delete DoEvents XLFL1.Delete End Sub Code :
Sub Redimensionnement() If ActiveWindow.Selection.ShapeRange.Height > ActiveWindow.Selection.ShapeRange.Width Then ActiveWindow.Selection.Cut With ActivePresentation.PageSetup .SlideOrientation = msoOrientationVertical End With DoEvents ActiveWindow.View.Paste With ActiveWindow.Selection.ShapeRange .Height = 720# .Width = .Width * .Height / 720# .Left = 0# .Top = 0# End With Else ActiveWindow.Selection.Cut With ActivePresentation.PageSetup .SlideOrientation = msoOrientationHorizontal End With DoEvents ActiveWindow.View.Paste With ActiveWindow.Selection.ShapeRange .Height = .Height * 720# / .Width .Width = 720# .Left = 0# .Top = 0# End With End If End Sub Avant réduction : 6,88 Go (7 398 482 266 octets) Après réduction : 258 Mo (271 285 708 octets) Temps d'exécution : Environ une heure pour 1869 images dans une vingtaine de dossiers (juste le temps de prendre un apéritif et un déjeuner frugal...) En insertion dans un document Word ou un classeur Excel, en diaporama ou en utilisant l'Aperçu de Windows, les photos réduites sont aussi nettes à l'écran que les originales (A ne pas utiliser pour une projection sur grand écran)
__________________
Je...ne...réponds...pas....aux...questions...techniques... par...mp La recherche (VBA-E) : Le Forum, La FAQ, Les cours et tutoriels, Contribuez, Les Sources et... l'Aide en ligne !!!
Dernière modification par ouskel'n'or ; 19/08/2008 à 10h52 |
|
|
|
|
|
|
#2 (permalink) | ||
![]() Date d'inscription: février 2005
Localisation: Une petite rue qui "avait" un merle
Messages: 11 637
|
Pour ceux qui souhaitent que le répertoire "miroir" "parent" soit créé automatiquement, dans la procédure Appel(), remplacer les lignes
Citation:
Code :
On Error Resume Next ChDir NewPath If Err <> 0 Then CreationRep NewPath End If On Error GoTo 0 Code :
Sub CreationRep(rep) Dim tablo, temp As String, i As Integer tablo = Split(rep, "\") ChDrive (Left(tablo(0), 1)) temp = tablo(0) & "\" On error resume next For i = 1 To UBound(tablo) - 1 temp = temp & tablo(i) If Dir(temp & "\") = "" Then MkDir temp End If temp = temp & "\" Next On error goto 0 End Sub Citation:
Code :
tablo = Split97(rep, "\") Code :
Function Split97(LeString as string, separateur as string) Dim Temp As String, LeTablo() Temp = LeString Do i = i + 1 ReDim Preserve LeTablo(i) If InStr(Temp, separateur) <> 0 Then LeTablo(i) = Left(Temp, InStr(Temp, separateur) - 1) Temp = Right(Temp, Len(Temp) - InStr(Temp, separateur)) Else LeTablo(i) = Temp End If Loop While InStr(Temp, separateur) <> 0 Splitt = LeTablo End Function ![]() (Mince ! Ma basket est percée, va falloir que j'en change Taille avant réduction : 4 Mo 57 Taille après réduction : 272 ko
__________________
Je...ne...réponds...pas....aux...questions...techniques... par...mp La recherche (VBA-E) : Le Forum, La FAQ, Les cours et tutoriels, Contribuez, Les Sources et... l'Aide en ligne !!!
Dernière modification par ouskel'n'or ; 19/08/2008 à 10h53 |
||
|
|
|
|
![]() |
![]() |
||
Réduire la taille d'images sans nuire à la qualité d'affichage à l'écran
|
||
| Outils de la discussion | |
|
|