PDA

View Full Version : Solved: Programmatically importing pictures from a URL



ukemike
05-06-2005, 12:49 PM
Hi guys,

I was wondering if anyone ever do any importing of pictures from the web into a word document.
I basically have a word document with a bookmark in it. I need to import an image from http://www.ssssss.com/sss/ss.jpg into where this bookmark is.
Thats part one. The second part is basically to make it fit in the rectangular shape that is around the bookmark. So i guess just resizing the image.
I was using Macro record to import the picture from the website (Import->Picture from File). It worked. The only problem is for some reason when you are in macro record mode you cannot resize the image you just imported. So after i stopped the recording, the picture was its original size and i could not get the code how to resize it.

Did anyone ever do this sort of thing??


Thanks
Mike

ukemike
05-06-2005, 02:08 PM
Hey guys,
One more quick question. I am doing a find/replace on a word document. I have a couple of Text Boxes in my Word document. The Find/Replace finds everything except the text that is in my TextBoxes. Anyone have any idea how i can modify this search to make it "Find" through the textboxes too?.
Maybe if there is no way to do this, someone can suggest how i can insert text in a certain point in a Word document without the word document expanding.
Like if the inserted 2 lines to a 10 line word document, the document would still be 10 lines long and not 12. Basically overwrite stuff.
I am using Word 2003

Any help would be greatly appreciated.

Thank you very much
Mike

MOS MASTER
05-07-2005, 01:41 PM
Hi guys,

I was wondering if anyone ever do any importing of pictures from the web into a word document.
I basically have a word document with a bookmark in it. I need to import an image from http://www.ssssss.com/sss/ss.jpg into where this bookmark is.
Thats part one. The second part is basically to make it fit in the rectangular shape that is around the bookmark. So i guess just resizing the image.
I was using Macro record to import the picture from the website (Import->Picture from File). It worked. The only problem is for some reason when you are in macro record mode you cannot resize the image you just imported. So after i stopped the recording, the picture was its original size and i could not get the code how to resize it.

Did anyone ever do this sort of thing??


Thanks
Mike
Hi Mike, :D

Inserting a picture shape in to the document at a very specific place is really not that easy, it involves many cave-at's!

But if you're using shapes this will probably work for you:
Option Explicit
Private Type PicProps
Height As Double
Width As Double
Top As Double
RTop As Integer
Left As Double
RLeft As Integer
End Type
Sub AddMyPicture()
Dim oShape As Word.Shape
Dim oPic As PicProps

With Application
.ScreenUpdating = False
.ActiveDocument.Bookmarks("bmShape").Select

Set oShape = .Selection.ShapeRange(1)

With oShape
oPic.Height = .Height
oPic.Width = .Width
oPic.Left = .Left
oPic.RLeft = .RelativeHorizontalPosition
oPic.Top = .Top
oPic.RTop = .RelativeVerticalPosition
End With

Set oShape = .ActiveDocument.Shapes.AddPicture _
(FileName:="http://www.vbaexpress.com/images/vbaxlogo.gif")
With oShape
.Height = oPic.Height
.Width = oPic.Width
.RelativeHorizontalPosition = oPic.RLeft
.Left = oPic.Left
.RelativeVerticalPosition = oPic.RTop
.Top = oPic.Top
End With
End With

Set oShape = Nothing
End Sub


See Attachment for a demo of the sub (ALT+F8 to run)

Enjoy! :thumb

MOS MASTER
05-07-2005, 01:44 PM
Hey guys,
One more quick question. I am doing a find/replace on a word document. I have a couple of Text Boxes in my Word document. The Find/Replace finds everything except the text that is in my TextBoxes. Anyone have any idea how i can modify this search to make it "Find" through the textboxes too?.
Maybe if there is no way to do this, someone can suggest how i can insert text in a certain point in a Word document without the word document expanding.
Like if the inserted 2 lines to a 10 line word document, the document would still be 10 lines long and not 12. Basically overwrite stuff.
I am using Word 2003

Any help would be greatly appreciated.

Thank you very much
Mike
Hi Mike, :D

No need to re?nvent the wheel over here.

Just use Word MVP's Doug Roubbins sub:
http://word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

Enjoy!