Private Sub CommandButton2_Click() Image1.PictureSizeMode = fmPictureSizeModeZoom'tu peux modifier Image1.Picture = LoadPicture("Chemin du fichier.jpg") End Sub
Private Sub CommandButton1_Click() With Application.FileDialog(msoFileDialogOpen) .AllowMultiSelect = False .Show TextBox1.Text = .SelectedItems(1) 'inscrit le chmin dans un TextBox End With Selection.InlineShapes.AddPicture FileName:=TextBox1.Text, LinkToFile:=False, SaveWithDocument:=True End Sub
Sub redimensionnerImage() Dim Img As WIA.ImageFile, IP As WIA.ImageProcess 'Création conteneur pour l'image à manipuler Set Img = CreateObject("WIA.ImageFile") 'Création du gestionnaire de filtre Set IP = CreateObject("WIA.ImageProcess") 'Chargement de l'image dans le conteneur Img.LoadFile "C:\fourmiz.JPG" 'Ajoute le filtre pour redimensionner l'image (Scale) IP.Filters.Add IP.FilterInfos("Scale").FilterID 'Définit la largeur maxi pour le redimensionnement IP.Filters(1).Properties("MaximumWidth") = 90 'Définit la hauteur maxi pour le redimensionnement IP.Filters(1).Properties("MaximumHeight") = 90 'remarque : 'Les proportions sont conservées. Le filtre prend en compte 'les ratios et adapte la taille pour ne pas dépasser les valeurs maxi définies. 'Application du filtre à l'image Set Img = IP.Apply(Img) 'Enregistre l'image redimensionnée Img.SaveFile "C:\fourmizThumbnail.JPG" End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionImage1.PictureSizeMode = fmPictureSizeModeStretch
Image1.PictureSizeMode = fmPictureSizeModeZoom
Dim image As Integer 'ouvrir fichier image Private Sub CommandButton1_Click() 'Declare a variable as a FileDialog object. Dim fd As FileDialog Dim fichier As String 'Create a FileDialog object as a File Picker dialog. Set fd = Application.FileDialog(msoFileDialogFilePicker) 'Declare a variable to contain the path 'of each selected item. Even though the path is a String, 'the variable must be a Variant because For Each...Next 'routines only work with Variants and Objects. Dim vrtSelectedItem As Variant 'Use a With...End With block to reference the FileDialog object. With fd 'Add a filter that includes GIF and JPEG images and make it the first item in the list. .Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1 'Use the Show method to display the File Picker dialog box and return the user's action. 'If the user presses the action button... If .Show = -1 Then 'Step through each string in the FileDialogSelectedItems collection. For Each vrtSelectedItem In .SelectedItems 'vrtSelectedItem is a String that contains the path of each selected item. 'You can use any file I/O functions that you want to work with this path. 'This example simply displays the path in a message box. fichier = vrtSelectedItem Next vrtSelectedItem 'If the user presses Cancel... Else End If End With 'Set the object variable to Nothing. Set fd = Nothing If fichier = "" Then Exit Sub 'inserer image Selection.InlineShapes.AddPicture FileName:=fichier, LinkToFile:=False, SaveWithDocument:=True 'aperçu image userForm Image1.PictureSizeMode = fmPictureSizeModeZoom Image1.Picture = LoadPicture(fichier) 'redimensionner NbreShape ActiveDocument.InlineShapes(image).Width = 100 'largeur ActiveDocument.InlineShapes(image).Height = 75 'hauteur End Sub Private Sub NbreShape() 'nbre d'images Set doc = ActiveDocument image = doc.InlineShapes.Count End Sub
'ouvrir fichier image Private Sub CommandButton1_Click() 'Declare a variable as a FileDialog object. Dim Img As WIA.ImageFile Dim fd As FileDialog Dim fichier As String Dim image As Integer Dim hauteur As Integer Dim largeur As Integer 'Create a FileDialog object as a File Picker dialog. Set fd = Application.FileDialog(msoFileDialogFilePicker) 'Declare a variable to contain the path 'of each selected item. Even though the path is a String, 'the variable must be a Variant because For Each...Next 'routines only work with Variants and Objects. Dim vrtSelectedItem As Variant 'Use a With...End With block to reference the FileDialog object. With fd 'Add a filter that includes GIF and JPEG images and make it the first item in the list. .Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1 'Use the Show method to display the File Picker dialog box and return the user's action. 'If the user presses the action button... If .Show = -1 Then 'Step through each string in the FileDialogSelectedItems collection. For Each vrtSelectedItem In .SelectedItems 'vrtSelectedItem is a String that contains the path of each selected item. 'You can use any file I/O functions that you want to work with this path. 'This example simply displays the path in a message box. fichier = vrtSelectedItem Next vrtSelectedItem 'If the user presses Cancel... Else End If End With 'Set the object variable to Nothing. Set fd = Nothing If fichier = "" Then Exit Sub 'inserer image Selection.InlineShapes.AddPicture FileName:=fichier, LinkToFile:=False, SaveWithDocument:=True 'aperçu image userForm Image1.PictureSizeMode = fmPictureSizeModeZoom Image1.Picture = LoadPicture(fichier) 'redimensionner Set Img = CreateObject("WIA.ImageFile") Img.LoadFile fichier ' chemin du fichier source largeur = Img.Width 'largeur de l'image hauteur = Img.Height 'hauteur de l'image If largeur > hauteur Then image = ActiveDocument.InlineShapes.Count 'nbre d'images ActiveDocument.InlineShapes(image).Width = 100 'largeur ActiveDocument.InlineShapes(image).Height = 75 'hauteur Else image = ActiveDocument.InlineShapes.Count 'nbre d'images ActiveDocument.InlineShapes(image).Width = 75 'largeur ActiveDocument.InlineShapes(image).Height = 100 'hauteur End If End Sub
UserForm1.Image1.Picture = LoadPicture(chemin_de_l'image)
'ouvrir fichier image Private Sub CommandButton1_Click() 'Declare a variable as a FileDialog object. Dim fd As FileDialog Dim fichier As String Dim image As Integer Dim hauteur As Integer Dim largeur As Integer 'Create a FileDialog object as a File Picker dialog. Set fd = Application.FileDialog(msoFileDialogFilePicker) 'Declare a variable to contain the path 'of each selected item. Even though the path is a String, 'the variable must be a Variant because For Each...Next 'routines only work with Variants and Objects. Dim vrtSelectedItem As Variant 'Use a With...End With block to reference the FileDialog object. With fd 'Add a filter that includes GIF and JPEG images and make it the first item in the list. .Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1 'Use the Show method to display the File Picker dialog box and return the user's action. 'If the user presses the action button... If .Show = -1 Then 'Step through each string in the FileDialogSelectedItems collection. For Each vrtSelectedItem In .SelectedItems 'vrtSelectedItem is a String that contains the path of each selected item. 'You can use any file I/O functions that you want to work with this path. 'This example simply displays the path in a message box. fichier = vrtSelectedItem Next vrtSelectedItem 'If the user presses Cancel... Else End If End With 'Set the object variable to Nothing. Set fd = Nothing If fichier = "" Then Exit Sub 'inserer image Selection.InlineShapes.AddPicture FileName:=fichier, LinkToFile:=False, SaveWithDocument:=True 'aperçu image userForm Image1.PictureSizeMode = fmPictureSizeModeZoom Image1.Picture = LoadPicture(fichier) 'redimensionner Image1.AutoSize = True largeur = UserForm1.Image1.Width 'largeur de l'image hauteur = UserForm1.Image1.Height 'hauteur de l'image If largeur > hauteur Then image = ActiveDocument.InlineShapes.Count 'nbre d'images ActiveDocument.InlineShapes(image).Width = 100 'largeur ActiveDocument.InlineShapes(image).Height = 75 'hauteur Else image = ActiveDocument.InlineShapes.Count 'nbre d'images ActiveDocument.InlineShapes(image).Width = 75 'largeur ActiveDocument.InlineShapes(image).Height = 100 'hauteur End If Image1.Width = 60 'a modifier Image1.Height = 60 'a modifier End Sub
Option Explicit Dim image, hauteur, largeur As Integer 'ouvrir fichier image Private Sub CommandButton1_Click() Dim objDoc As Document, objShape As InlineShape 'Declare a variable as a FileDialog object. Dim fd As FileDialog Dim Fichier As String 'Create a FileDialog object as a File Picker dialog. Set fd = Application.FileDialog(msoFileDialogFilePicker) 'Declare a variable to contain the path 'of each selected item. Even though the path is a String, 'the variable must be a Variant because For Each...Next 'routines only work with Variants and Objects. Dim vrtSelectedItem As Variant 'Use a With...End With block to reference the FileDialog object. With fd 'Add a filter that includes GIF and JPEG images and make it the first item in the list. .Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1 'Use the Show method to display the File Picker dialog box and return the user's action. 'If the user presses the action button... If .Show = -1 Then 'Step through each string in the FileDialogSelectedItems collection. For Each vrtSelectedItem In .SelectedItems 'vrtSelectedItem is a String that contains the path of each selected item. 'You can use any file I/O functions that you want to work with this path. 'This example simply displays the path in a message box. Fichier = vrtSelectedItem Next vrtSelectedItem 'If the user presses Cancel... Else End If End With 'Set the object variable to Nothing. Set fd = Nothing If Fichier = "" Then Exit Sub 'inserer image et redimensionner à modifier si necessaire Set objShape = Selection.InlineShapes.AddPicture(FileName:=Fichier, LinkToFile:=False, SaveWithDocument:=True) With objShape .LockAspectRatio = msoTrue .Height = .Height * 0.25 'réduit l'image .Width = .Width * 0.25 'réduit l'image End With 'charger image userForm Image1.Picture = LoadPicture(Fichier) 'aperçu image userForm Image1.AutoSize = True largeur = UserForm1.Image1.Width 'largeur de l'image hauteur = UserForm1.Image1.Height 'hauteur de l'image If largeur > hauteur Then 'mode paysage With Image1 .BackColor = &H8000000F .PictureSizeMode = fmPictureSizeModeZoom .Width = 100 'a modifier .Height = 70 'a modifier End With ElseIf largeur = hauteur Then 'mode carré With Image1 .BackColor = &H8000000F 'couleur de l'UserForm(blanche)à modifier si necessaire .PictureSizeMode = fmPictureSizeModeZoom .Width = 100 'a modifier .Height = 100 'a modifier End With Else 'mode portrait With Image1 .BackColor = &H8000000F .PictureSizeMode = fmPictureSizeModeZoom .Width = 85 'a modifier .Height = 100 'a modifier End With End If End Sub 'suppression de la dernière image Private Sub CommandButton2_Click() image = ActiveDocument.InlineShapes.Count 'nbre d'images ActiveDocument.InlineShapes(image).Delete 'supprime la dernière image End Sub 'suppression de toutes les images Private Sub CommandButton3_Click() Dim intResponse As Integer intResponse = MsgBox("Etes-vous sûr de vouloir " & _ "supprimer toutes les images?", vbYesNo) If intResponse = vbYes Then ActiveDocument.Content.Select Selection.Delete End If End Sub Private Sub UserForm_Initialize() Me.Caption = "Inserer image" With CommandButton1 .Caption = "Rechercher image" .AutoSize = True End With With CommandButton2 .Caption = "Supprimer dernière image" .AutoSize = True End With With CommandButton3 .Caption = "Supprimer toutes les images" .AutoSize = True End With End Sub
'suppression de la dernière image Private Sub CommandButton2_Click() image = ActiveDocument.InlineShapes.Count 'nbre d'images ActiveDocument.InlineShapes(image).Delete 'supprime la dernière image End Sub 'suppression de toutes les images Private Sub CommandButton3_Click() Dim intResponse As Integer intResponse = MsgBox("Etes-vous sûr de vouloir " & _ "supprimer toutes les images?", vbYesNo) If intResponse = vbYes Then ActiveDocument.Content.Select Selection.Delete End If End Sub Private Sub UserForm_Initialize() Me.Caption = "Inserer image" With CommandButton1 .Caption = "Rechercher image" .AutoSize = True End With With CommandButton2 .Caption = "Supprimer dernière image" .AutoSize = True End With With CommandButton3 .Caption = "Supprimer toutes les images" .AutoSize = True End With