PDA

View Full Version : Inserting a LOGO



Kindly_Kaela
12-18-2006, 12:19 PM
Hi Everyone!

I am in search of VBA coding that will allow the user to insert a picture into a word document.

I'm building a customer proposal generator. The customer's company logo would look great on the opening page. What code would you recommend I use? Ideally, a browser window would appear and the user would find the saved image.

Please advise.

Thank you!
Kaela :cloud9:

lucas
12-18-2006, 12:33 PM
Try this to insert at the cursor:

Option Explicit
Sub InsPic()

' The default folder for pictures is set under Tools-Options-File Locations.
'This macro uses the Insert Picture from File command to open that
'dialog box pointing to the default pictures folder.

Application.Dialogs(wdDialogInsertPicture).Show

End Sub

Kindly_Kaela
12-18-2006, 12:50 PM
Thanks Steve, the code worked. But I am now thinking this may cause problems for the final document because there is no way of knowing how big the users image will be. So depending on the size, the cover page may not look nice by pushing the bottom text to a new page.

Know what I mean? Does anyone have an idea around that?

lucas
12-18-2006, 01:39 PM
Kaela,
This works for me but I don't think it's the correct way to select the picture.....maybe Gerry will give us a pointer when he comes along.
Option Explicit
Sub Logo()
Application.Dialogs(wdDialogInsertPicture).Show
Selection.WholeStory
Selection.InlineShapes(1).Height = 50
Selection.InlineShapes(1).Width = 50
End Sub

Bilby
12-18-2006, 01:55 PM
Greetings,

I have an application that inserts and correctly captions a user selected graphic. The code gives the user the option of full width of the text column, or a specific graphic height. In the case of a cover card the user
is restricted to a set of graphics that are created specifically to fit on the covercard.

First problem is that in order to control the size of a graphic you need to select it. The following code inserts a graphic into a bookmark and becouse theres only one graphic inserted by the code its count will always be 1 no matter how many other graphics are in the document.

With ActiveDocument
.InlineShapes.AddPicture FileName:=strDesignPath, LinkToFile:=True _
, SaveWithDocument:=True, Range:=ActiveDocument.Bookmarks("CrPlace").Range
.InlineShapes.Item(ActiveDocument.InlineShapes.Count).Select
End With

At this point you can do some maths to calculate the final graphics size.
Selection.InlineShapes(1).Width & Selection.InlineShapes(1).Height give you the graphics un-resized dimensions while Selection.PageSetup.TextColumns.Width gives you the width of the text column the cursor is currently in, etc.

The basic principle is bookmark the cursor position.
Insert & immediately select the graphic
change the height/width of the graphic to suit.

This is probably an inelegant way of doing it but it works for me and while it works I'll probably leave it alone, though If anyone has a more efficient way of selecting/controlling graphics I'd be happy to hear from them.

Edit by Lucas: Line break added for folks with small monitors

fumei
12-19-2006, 08:40 AM
There is simply no way around the fact that Word is NOT a graphic application. It is a word processor. Yes, you can insert an image. Yes, it is possible to do some resizing of that image, by code, after the fact.

However, it is not elegant. Why not just have the user grab the image handles in the document and do the resizing?


First problem is that in order to control the size of a graphic you need to select it. Actually, this is not correct. You do not need to select the image to action it.

Any image that is placed into the document is in the InlineShapes (or Shapes) collection, and can be action directly using that collection. It is messy, and likely the least intuitive part of the Word object model.

Therefore, it is true the EASIEST way to resize images is by selecting it, but technically...you do not need to select it.