AndrewMc
11-05-2013, 07:37 PM
Hi All
I regularly copy and paste images from a graphics package into a Word document, then need to resize and crop the images. I am trying to develop a Word addin that will make this process easier. Copying and pasting the images is easy, but editing each image size is tedious (involving lots of scrolling through the document and right-clicking on each image).
Instead, I want to have a macro that displays a form that shows the size and margin settings for a picture along with settings I can modify and apply to the picture. I want the form to have buttons "Previous" and "Next" to jump the previous or next image (if there is one).
Currently, I have developed a procedure to create an array listing the index numbers of all of the inline shapes in the document that are a picture type (ThisDocument.InlineShape(index).Type=wdInlineShapePicture).
I have another procedure that displays the picture size and margin cropping information in a simple form.
Now I am stuck. While I can get the form opening with the information from the first image, I cannot work out the logic to get the "Previous" and "Next" buttons to load the form with new information. The code for the main procedure is shown below:
Sub FigureSizeManipulation()
Dim wd As Document
Set wd = ThisDocument
If wd.InlineShapes.Count > 0 Then
Dim alPictureList() As Long 'array to hold index numbers of picture shapes
'''get array if inlineshape picture index values; return False if none found
If GetPictureList(alPictureList) Then
glIndex = 1 'global: array index number
MsgBox UBound(alPictureList) & " inline picture shapes found!", vbInformation
'''show form with info from InlineShape(alPictureList(glIndex))
Call ShowForm(alPictureList)
Else
MsgBox "No inline picture shapes found!", vbCritical
End If
Else
MsgBox "No inline shapes found!", vbCritical
End If
End Sub
The code for the "Previous" and "Next" buttons is:
Private Sub cmdPrevious_Click()
'decrement the array index number
glIndex = glIndex - 1
End Sub
Private Sub cmdNext_Click()
'increment the array index number
glIndex = glIndex + 1
End Sub
I have used a global variable to store the index of the array value to display, but the array is only a local variable. Should I make the array global so that the cmdPrevious_Click() and cmdNext_Click() procedures can call ShowForm() to display the new info?
Or instead, should I redesign the project and use Find to search for graphics "^g", and move through the document to each image?
Does anyone have any suggestions (or pseudocode) for a way to do what I am wanting?
Cheers
Andrew Mc
I regularly copy and paste images from a graphics package into a Word document, then need to resize and crop the images. I am trying to develop a Word addin that will make this process easier. Copying and pasting the images is easy, but editing each image size is tedious (involving lots of scrolling through the document and right-clicking on each image).
Instead, I want to have a macro that displays a form that shows the size and margin settings for a picture along with settings I can modify and apply to the picture. I want the form to have buttons "Previous" and "Next" to jump the previous or next image (if there is one).
Currently, I have developed a procedure to create an array listing the index numbers of all of the inline shapes in the document that are a picture type (ThisDocument.InlineShape(index).Type=wdInlineShapePicture).
I have another procedure that displays the picture size and margin cropping information in a simple form.
Now I am stuck. While I can get the form opening with the information from the first image, I cannot work out the logic to get the "Previous" and "Next" buttons to load the form with new information. The code for the main procedure is shown below:
Sub FigureSizeManipulation()
Dim wd As Document
Set wd = ThisDocument
If wd.InlineShapes.Count > 0 Then
Dim alPictureList() As Long 'array to hold index numbers of picture shapes
'''get array if inlineshape picture index values; return False if none found
If GetPictureList(alPictureList) Then
glIndex = 1 'global: array index number
MsgBox UBound(alPictureList) & " inline picture shapes found!", vbInformation
'''show form with info from InlineShape(alPictureList(glIndex))
Call ShowForm(alPictureList)
Else
MsgBox "No inline picture shapes found!", vbCritical
End If
Else
MsgBox "No inline shapes found!", vbCritical
End If
End Sub
The code for the "Previous" and "Next" buttons is:
Private Sub cmdPrevious_Click()
'decrement the array index number
glIndex = glIndex - 1
End Sub
Private Sub cmdNext_Click()
'increment the array index number
glIndex = glIndex + 1
End Sub
I have used a global variable to store the index of the array value to display, but the array is only a local variable. Should I make the array global so that the cmdPrevious_Click() and cmdNext_Click() procedures can call ShowForm() to display the new info?
Or instead, should I redesign the project and use Find to search for graphics "^g", and move through the document to each image?
Does anyone have any suggestions (or pseudocode) for a way to do what I am wanting?
Cheers
Andrew Mc