l0aded
07-23-2014, 03:25 PM
Hey guys sorry I am fairly new to VBA and have searched around but cannot figure out how to code what I am trying to do.
Basically I want to add an image with the same name as the first word in the paragraph before that word; this macro will be to add images into an inventory list.
So far I have something like this:
=========
Sub FAXP()
n = 20
While counter <> "-----------------------------------------------------------------------------"
counter = ActiveDocument.Paragraphs(n). _
Range.Words(1)
If counter <> "-----------------------------------------------------------------------------" Then
ActiveDocument.Paragraphs(n). _
Range.InsertBefore "Picture "
End If
n = n + 1
Wend
End Sub
=========
I found a macro to resize all the pictures after they are inserted but I do not know how to insert images correctly yet, especially with a variable filename :think:. Can someone provide some direction so that instead of inserting the words "Picture " it will insert the picture with the same name as the counter variable? I hope I am explaining it correctly.
I imagine I would need to made a separate macro to be called, something like this:
=========
Sub InsertImage()
Dim rng As Range
Dim vShape As InlineShape
Set vShape = Selection.InlineShapes.AddPicture(FileName:="C:\Users\Person\Desktop" & VARIABLEcounter?? & ".png", LinkToFile:= _
False, SaveWithDocument:=True)
With vShape
.LockAspectRatio = True
.Height = InchesToPoints(1)
End With
End Sub
=========
Thanks!
Basically I want to add an image with the same name as the first word in the paragraph before that word; this macro will be to add images into an inventory list.
So far I have something like this:
=========
Sub FAXP()
n = 20
While counter <> "-----------------------------------------------------------------------------"
counter = ActiveDocument.Paragraphs(n). _
Range.Words(1)
If counter <> "-----------------------------------------------------------------------------" Then
ActiveDocument.Paragraphs(n). _
Range.InsertBefore "Picture "
End If
n = n + 1
Wend
End Sub
=========
I found a macro to resize all the pictures after they are inserted but I do not know how to insert images correctly yet, especially with a variable filename :think:. Can someone provide some direction so that instead of inserting the words "Picture " it will insert the picture with the same name as the counter variable? I hope I am explaining it correctly.
I imagine I would need to made a separate macro to be called, something like this:
=========
Sub InsertImage()
Dim rng As Range
Dim vShape As InlineShape
Set vShape = Selection.InlineShapes.AddPicture(FileName:="C:\Users\Person\Desktop" & VARIABLEcounter?? & ".png", LinkToFile:= _
False, SaveWithDocument:=True)
With vShape
.LockAspectRatio = True
.Height = InchesToPoints(1)
End With
End Sub
=========
Thanks!