View Single Post
 
Old 10-23-2012, 04:37 PM
ralphpickering ralphpickering is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Oct 2012
Location: London
Posts: 4
ralphpickering is on a distinguished road
Default

Thanks Paul. I'm going to try some of those ideas in updating the macros I put together yesterday from bits I found on the Internet. I particularly like the use of PageWidth and PageHeight. I ended up using 2 macros - one to select and insert the Image, and the other to scale and position it.

As far as converting the PDF is concerned, this is pretty much a last resort. The main problem is that the PDF is just made up of flat images - there's not much for a conversion tool to work with. Abbyy FineReader made the best attempt, using the OCR'd text behind the PDF image (outputting as PDF), but for some reason it reduces the image quality which wasn't brilliant to begin with - and of course I couldn't see how well it had managed to interpret the text. Outputting as a Word Document showed that it hadn't done particularly well at all, even with a load of manual training of the OCR engine. Eventually I gave up and chose unformatted text from the OCR and started recreating the documents manually.

Anyway, this is the code I've come up with, in two parts because it seems that the picture doesn't gain focus after the first macro inserts it, and so using With Selection fails.

Quote:
Sub InsertPicture()
Dim oDialog As Word.Dialog

Set oDialog = Dialogs(wdDialogInsertPicture)

With oDialog
.Display
If .Name <> "" Then
ActiveDocument.Shapes.AddPicture FileName:=.Name, _
LinkToFile:=False, _
SaveWithDocument:=True, _
Left:=0, _
Top:=0, _
Width:=CentimetersToPoints(21), _
Height:=CentimetersToPoints(29.7), _
Anchor:=Selection.Range
End If
End With

Set oDialog = Nothing

End Sub

Sub FormatPicture()

Dim Shp As Shape

With Selection
If .InlineShapes.Count = 1 Then
Set Shp = .InlineShapes(1).ConvertToShape
Else
Set Shp = .ShapeRange(1)
End If
With Shp
With .WrapFormat
.Type = wdWrapBehind
.DistanceTop = InchesToPoints(0.1)
.DistanceBottom = InchesToPoints(0.1)
End With
With .Line
.Weight = 1#
.Visible = False
End With
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.LeftRelative = 0
.TopRelative = 0
.PictureFormat.Brightness = .PictureFormat.Brightness + 0.1

End With
End With
End Sub
Reply With Quote