Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

Toolbutton to Format Picture

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ruth Ivimey-Cook - 07 Jun 2005 19:42 GMT
Hi,

I want a toolbar button that will apply my "standard" formatting to a
picture (e.g. tiff) that I insert in the document. I've found out some
things, but don't think I've got there yet. In particular, I worry that my
converted shape (in "pict") is not re-added to the document.

Lastly, is there a way to disable/enable the associated toolbutton if the
selection is/is not of an acceptable type?

Thanks

Ruth

' Apply a standard format to an inlineshape or floating shape that is the
' currently selected thing in the document.
Sub StdFormatPicture()
   Dim pict As shape
   
   ' Pictures get inserted as inline shapes. so it's likely
   ' that the selection is one. It must be converted to a
   ' floating shape before formatting.
   pict = Nothing
   If Selection.Type = wdSelectionInlineShape Then
       pict = Selection.ConvertToShape
   ElseIf Selection.Type = wdSelectionShape Then
       pict = Selection
   End If
   
   ' If we have something to play with it should be
   ' a full "Shape" ...
   If pict <> Nothing Then
       With pict.ShapeRange
           .Fill.Visible = msoFalse
           .Line.Visible = msoFalse
           .LockAspectRatio = msoTrue
           .Rotation = 0#
           .PictureFormat.Brightness = 0.5
           .PictureFormat.Contrast = 0.5
           .PictureFormat.ColorType = msoPictureAutomatic
           .PictureFormat.CropLeft = 0#
           .PictureFormat.CropRight = 0#
           .PictureFormat.CropTop = 0#
           .PictureFormat.CropBottom = 0#
           .RelativeHorizontalPosition = _
               wdRelativeHorizontalPositionColumn
           .RelativeVerticalPosition = _
               wdRelativeVerticalPositionParagraph
           .Left = wdShapeCenter
           .Top = InchesToPoints(0)
           .LockAnchor = False
           .LayoutInCell = True
           .WrapFormat.AllowOverlap = False
           .WrapFormat.Side = wdWrapBoth
           .WrapFormat.DistanceTop = InchesToPoints(0.1)
           .WrapFormat.DistanceBottom = InchesToPoints(0.1)
           .WrapFormat.DistanceLeft = InchesToPoints(0.1)
           .WrapFormat.DistanceRight = InchesToPoints(0.1)
           .WrapFormat.Type = wdWrapTopBottom
       End With
   End If

End Sub
Cindy M  -WordMVP- - 08 Jun 2005 13:53 GMT
Hi Ruth,

> I want a toolbar button that will apply my "standard" formatting to a
> picture (e.g. tiff) that I insert in the document. I've found out some
> things, but don't think I've got there yet. In particular, I worry that my
> converted shape (in "pict") is not re-added to the document.
>  
Since you really don't give us any details, it's impossible to offer an
opinion. What, exactly, is the problem, and show us the code involved. Also
tell us which version of Word you're using.

> Lastly, is there a way to disable/enable the associated toolbutton if the
> selection is/is not of an acceptable type?

Depends, but certainly no simple way. Under certain circumstances one could
use the Window_SelectionChangeEvent. But that by itself might not do the job.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
Ruth Ivimey-Cook - 09 Jun 2005 18:07 GMT
Cindy,
> Since you really don't give us any details, it's impossible to offer an
> opinion. What, exactly, is the problem, and show us the code involved. Also
> tell us which version of Word you're using.

Sorry. I'm using Office Word 2003 SP1.

The problem was to insert a picture (TIFF or EPS) into a doc file quickly,
as I have quite a lot of them, and when doing things using the standard
picture toolbar button it inserts the picture as an inline shape, and I must
edit the advanced format settings to get it "right" - that is, wrap top &
bottom, centred within column, 0" from paragraph.

It's intended to be used from a toolbar button, and with the cursor on the
line that will become the anchor line.

After a bit more playing I ended up with the following code, which seems to
work ok now (so I'm posting this more for any thoughts and/or for your
curiosity).

Ruth

-8><-----------------------------------
Dim SavedDirectory As String

Sub CustomInsertPicture()
   Dim dlgOpenPicture As FileDialog
   Dim file As Variant
   
   On Error GoTo problem
   
   If SavedDirectory = "" Then
       SavedDirectory = "C:\"
   End If
   
   Set dlgOpenPicture = Application.FileDialog(msoFileDialogFilePicker)
   
   With dlgOpenPicture
       .AllowMultiSelect = False
       .InitialFileName = SavedDirectory
       .ButtonName = "Insert"
       .Title = "Insert Picture"
       .Filters.Clear
       ' Add a filter that includes all files.
       .Filters.Add "All files", "*.*"
       ' Add a filter that includes TIF, GIF and JPEG images and
       ' make it the first item in the list.
       .Filters.Add "Images", "*.tif; *.tiff; *.gif; *.jpg; *.jpeg", 1
   End With
   
   If dlgOpenPicture.Show = -1 Then
       
       Dim pict As shape
       SavedDirectory = dlgOpenPicture.InitialFileName
       
       For Each file In dlgOpenPicture.SelectedItems
       
           Set pict = ActiveDocument.Shapes.AddPicture(filename:=file, _
                       LinkToFile:=True, SaveWithDocument:=True, _
                       Anchor:=Selection.Range)
           
           If Not (pict Is Nothing) Then
               With pict
                   .Fill.Visible = msoFalse
                   .Line.Visible = msoFalse
                   .LockAspectRatio = msoTrue
                   .Rotation = 0#
                   .PictureFormat.Brightness = 0.5
                   .PictureFormat.Contrast = 0.5
                   .PictureFormat.ColorType = msoPictureAutomatic
                   .PictureFormat.CropLeft = 0#
                   .PictureFormat.CropRight = 0#
                   .PictureFormat.CropTop = 0#
                   .PictureFormat.CropBottom = 0#
                   .RelativeHorizontalPosition = _
                       wdRelativeHorizontalPositionColumn
                   .RelativeVerticalPosition = _
                       wdRelativeVerticalPositionParagraph
                   .Left = wdShapeCenter
                   .Top = InchesToPoints(0)
                   .LockAnchor = False
                   .LayoutInCell = False
                   .WrapFormat.AllowOverlap = False
                   .WrapFormat.Side = wdWrapBoth
                   .WrapFormat.DistanceTop = InchesToPoints(0.1)
                   .WrapFormat.DistanceBottom = InchesToPoints(0.1)
                   .WrapFormat.DistanceLeft = InchesToPoints(0.1)
                   .WrapFormat.DistanceRight = InchesToPoints(0.1)
                   .WrapFormat.Type = wdWrapTopBottom
               End With
           End If
       Next file
   End If
   Exit Sub
problem:
   MsgBox "There was a problem loading the picture.", vbExclamation
End Sub

-8><-----------------------------------
Cindy M  -WordMVP- - 11 Jun 2005 16:44 GMT
Hi Ruth,

> The problem was to insert a picture (TIFF or EPS) into a doc file quickly,
> as I have quite a lot of them, and when doing things using the standard
> picture toolbar button it inserts the picture as an inline shape, and I must
> edit the advanced format settings to get it "right" - that is, wrap top &
> bottom, centred within column, 0" from paragraph.

You do know Word 2003 allows you to determine the default wrapping style you
prefer? Tools/Options/Edit.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.