J
jgershonw1
I want to insert 3(rows)x2(cols) images per page into a document, but I
am having problems inserting the pagebreaks. I can't seem to get the
page break to occur after images. Right now, the images are pushed
down a page, thus mixing up the order and the first page ends up blank.
If anybody can help me with solving the problem, I would be very
grateful. Thanks!
Here is the following function that will take a directory of jpgs
inserts them into a document:
Public Sub InsertGraphicFiles(ByVal strDir As String)
Dim doc As Document
Dim ShapeGraph As Shape
Dim strFile As String
Dim arrFiles(10000) As String
Dim lngCount As Long
Dim lngWidth As Long
Dim lngHeight As Long
Dim lngLeftOffset As Long
Dim lngTopOffset As Long
Dim i As Long
Dim rngEnd As Word.Range
Set rngEnd = ActiveDocument.Range
lngWidth = 200
lngHeight = 170
Set doc = ActiveDocument
Dim ilshape As InlineShape
For Each ilshape In doc.InlineShapes
ilshape.Delete
Next
strFile = Dir(strDir & "\*.jpg")
i = 0
Do While strFile <> ""
arrFiles(i) = strDir & "\" & strFile
strFile = Dir
i = i + 1
Loop
lngCount = i - 1
lngLeftOffset = 20
lngTopOffset = 20
Dim lngMaxColsPerPage As Long
Dim lngMaxRowsPerPage As Long
Dim lngColCount As Long
Dim lngRowCount As Long
Dim lngLeft As Long
Dim lngTop As Long
lngMaxColsPerPage = 2
lngMaxRowsPerPage = 3
lngColCount = 0
lngRowCount = 0
lngLeft = lngLeftOffset
lngTop = lngTopOffset
For i = 0 To lngCount
Set ShapeGraph = doc.Shapes.AddPicture(FileName:=arrFiles(i),
LinkToFile:=False, SaveWithDocument:=True, Anchor:=Selection.Range)
ShapeGraph.Width = lngWidth
ShapeGraph.Height = lngHeight
If lngColCount > 0 Then
lngLeft = lngLeft + ShapeGraph.Width + 20
Else
lngLeft = lngLeftOffset
End If
ShapeGraph.Top = lngTop
ShapeGraph.Left = lngLeft
ShapeGraph.WrapFormat.Type = wdWrapThrough
lngColCount = lngColCount + 1
If lngColCount > lngMaxColsPerPage - 1 Then
lngTop = lngTop + ShapeGraph.Height + 20
lngLeft = lngLeftOffset
lngColCount = 0
lngRowCount = lngRowCount + 1
End If
If lngRowCount > lngMaxRowsPerPage - 1 Then
Selection.InsertBreak Type:=wdPageBreak
lngTop = lngTopOffset
lngRowCount = 0
End If
Next
End Sub
am having problems inserting the pagebreaks. I can't seem to get the
page break to occur after images. Right now, the images are pushed
down a page, thus mixing up the order and the first page ends up blank.
If anybody can help me with solving the problem, I would be very
grateful. Thanks!
Here is the following function that will take a directory of jpgs
inserts them into a document:
Public Sub InsertGraphicFiles(ByVal strDir As String)
Dim doc As Document
Dim ShapeGraph As Shape
Dim strFile As String
Dim arrFiles(10000) As String
Dim lngCount As Long
Dim lngWidth As Long
Dim lngHeight As Long
Dim lngLeftOffset As Long
Dim lngTopOffset As Long
Dim i As Long
Dim rngEnd As Word.Range
Set rngEnd = ActiveDocument.Range
lngWidth = 200
lngHeight = 170
Set doc = ActiveDocument
Dim ilshape As InlineShape
For Each ilshape In doc.InlineShapes
ilshape.Delete
Next
strFile = Dir(strDir & "\*.jpg")
i = 0
Do While strFile <> ""
arrFiles(i) = strDir & "\" & strFile
strFile = Dir
i = i + 1
Loop
lngCount = i - 1
lngLeftOffset = 20
lngTopOffset = 20
Dim lngMaxColsPerPage As Long
Dim lngMaxRowsPerPage As Long
Dim lngColCount As Long
Dim lngRowCount As Long
Dim lngLeft As Long
Dim lngTop As Long
lngMaxColsPerPage = 2
lngMaxRowsPerPage = 3
lngColCount = 0
lngRowCount = 0
lngLeft = lngLeftOffset
lngTop = lngTopOffset
For i = 0 To lngCount
Set ShapeGraph = doc.Shapes.AddPicture(FileName:=arrFiles(i),
LinkToFile:=False, SaveWithDocument:=True, Anchor:=Selection.Range)
ShapeGraph.Width = lngWidth
ShapeGraph.Height = lngHeight
If lngColCount > 0 Then
lngLeft = lngLeft + ShapeGraph.Width + 20
Else
lngLeft = lngLeftOffset
End If
ShapeGraph.Top = lngTop
ShapeGraph.Left = lngLeft
ShapeGraph.WrapFormat.Type = wdWrapThrough
lngColCount = lngColCount + 1
If lngColCount > lngMaxColsPerPage - 1 Then
lngTop = lngTop + ShapeGraph.Height + 20
lngLeft = lngLeftOffset
lngColCount = 0
lngRowCount = lngRowCount + 1
End If
If lngRowCount > lngMaxRowsPerPage - 1 Then
Selection.InsertBreak Type:=wdPageBreak
lngTop = lngTopOffset
lngRowCount = 0
End If
Next
End Sub