refer94
12-09-2016, 01:34 AM
Hey all,
I'm pretty new regarding VBA and macro so i hope that someone can help me.
I work with a lot of pictures and it can be difficult to arrange them and very time consumeing when it's sometimes 200+. I'm trying to make a code that can put them all in at once and arrange them for me.
I want my code to do the following.
1. Insert all pictures from a folder without having to individually select them all.
2. Scale all pictures to 450x450. (Can always be changed)
3. Insert the pictures, 2 on each word page (Landscape) and right centre the first and left centre the second.
So far i have made a code which does number 1 and 2 but i can't seem to figure out how to do number 3. Do i have to make som boxes for guidance?
Really hope you can help me. Kind regards
Thomas
This is my code so far if it helps anybody.
Sub InsertImages()
Dim intResult As Integer
Dim strPath As String
Dim strFolderPath As String
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
'the dialog is displayed to the user
intResult = Application.FileDialog(msoFileDialogFolderPicker).Show
'checks if user has cancled the dialog
If intResult <> 0 Then
'dispaly message box
strFolderPath = Application.FileDialog(msoFileDialogFolderPicker _
).SelectedItems(1)
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder(strFolderPath)
i = 1
'loops through each file in the directory and prints their names and path
For Each objFile In objFolder.Files
'get file path
strPath = objFile.path
'insert the image
Selection.InlineShapes.AddPicture FileName:= _
strPath, LinkToFile:=False, _
SaveWithDocument:=True
Next objFile
With ActiveDocument
For i = 1 To .InlineShapes.Count
With .InlineShapes(i)
.ScaleHeight = 55
.ScaleWidth = 60
End With
Next i
End With
End If
End Sub
I'm pretty new regarding VBA and macro so i hope that someone can help me.
I work with a lot of pictures and it can be difficult to arrange them and very time consumeing when it's sometimes 200+. I'm trying to make a code that can put them all in at once and arrange them for me.
I want my code to do the following.
1. Insert all pictures from a folder without having to individually select them all.
2. Scale all pictures to 450x450. (Can always be changed)
3. Insert the pictures, 2 on each word page (Landscape) and right centre the first and left centre the second.
So far i have made a code which does number 1 and 2 but i can't seem to figure out how to do number 3. Do i have to make som boxes for guidance?
Really hope you can help me. Kind regards
Thomas
This is my code so far if it helps anybody.
Sub InsertImages()
Dim intResult As Integer
Dim strPath As String
Dim strFolderPath As String
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim i As Integer
'the dialog is displayed to the user
intResult = Application.FileDialog(msoFileDialogFolderPicker).Show
'checks if user has cancled the dialog
If intResult <> 0 Then
'dispaly message box
strFolderPath = Application.FileDialog(msoFileDialogFolderPicker _
).SelectedItems(1)
'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Get the folder object
Set objFolder = objFSO.GetFolder(strFolderPath)
i = 1
'loops through each file in the directory and prints their names and path
For Each objFile In objFolder.Files
'get file path
strPath = objFile.path
'insert the image
Selection.InlineShapes.AddPicture FileName:= _
strPath, LinkToFile:=False, _
SaveWithDocument:=True
Next objFile
With ActiveDocument
For i = 1 To .InlineShapes.Count
With .InlineShapes(i)
.ScaleHeight = 55
.ScaleWidth = 60
End With
Next i
End With
End If
End Sub