Hello. I am hoping to find a macro which will allow me to insert an object (which will be a picture) that will automatically update itself, re-size itself and center itself upon opening. This will be used for large word documents that have references to data sheet images which change. When these data sheets change i would save them as the same name and file type as the original and then move the original file to an obsolete folder, eventually repeating this process once the data sheets change again. I currently have some bits of code which I am not sure how to integrate but this code to follow adds a image as an inline shape, upon running the file explorer opens so the user can select what image to place into the word document. After selecting the desired image it is re-sized and re-oriented. I am looking for a macro that will open the 'object' command in the insert tab, open the browse prompt for 'create from file' and then make it so the 'link to file' box is checked. At which point I would like the image re-sized and re-oriented. PLEASE HELP! ANY INPUT IS GREATLY APPRECIATED!
Sub Insert_picture_and_format()
'
' Insert_picture_and_format Macro
'
'
Dim oDialog As Dialog
Dim strFile As String
Dim oImage As Object
Dim oRng As Object
Set oDialog = Dialogs(wdDialogInsertPicture)
With oDialog
.Display
If .Name <> "" Then
strFile = .Name
End If
End With
Set oImage = Selection.InlineShapes.AddPicture(strFile)
With oImage
.LockAspectRatio = msoFalse
.Height = CentimetersToPoints(25)
.Width = CentimetersToPoints(19)
Set oRng = .ConvertToShape
End With
With oRng
.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = _
wdRelativeVerticalPositionPage
.Left = CentimetersToPoints(1.25)
.Top = CentimetersToPoints(1.25)
End With
Set oDialog = Nothing
Set oImage = Nothing
Set oRng = Nothing
End Sub
I also use a macro for updating file paths as soon as a document is opened (usually in reference to the document filepath itself, so that the location can be easily found by another person) I am not sure if this macro would come in handy for updating the object (which would be a image in this case) or if the linked image would automatically update upon opening the word document.
Sub AutoOpen()
'
' AutoOpen Macro
'
'
Dim aStory As Range
Dim aField As Field
For Each aStory In ActiveDocument.StoryRanges
For Each aField In aStory.Fields
aField.Update
Next aField
Next aStory
End Sub