Add Picture on the second page, but it appear on the first page

V

Victor Dong

I try Office 2000 + SP3, and Office 2003, the issue happen in both version
word. Below is my VB code


Private m_Document As Word.Document 'Word document object

Public Sub AddPicture(ByVal strFile As String, _
ByVal sngLeft As Single, _
ByVal sngTop As Single
ByVal sngWidth As Single, _
ByVal sngHeight As Single)

Dim sngTop As Single 'Top for picture
Dim spPicture As Word.Shape 'shape of picture

m_Document.InlineShapes.AddPicture strFile, True, True

Set spPicture =
m_Document.InlineShapes(m_Document.InlineShapes.Count).ConvertToShape

spPicture.RelativeHorizontalPosition =
wdRelativeHorizontalPositionPage
spPicture.RelativeVerticalPosition =
wdRelativeHorizontalPositionPage

spPicture.Left = (.sngWidth - .sngLeft - .sngRight - sngWidth) / 2
spPicture.Top = sngTop
spPicture.Width = sngWidth
spPicture.Height = sngHeight

‘Below is inserting Shape directly, but it has same issue
'm_Document.Shapes.AddPicture strFile, True, True, _
sngLeft , sngTop, sngWidth, sngHeight
End Sub
 
H

Helmut Weber

Hi Victor,

where is the insertion point
when trying to add the picture?

I can't see any routine here
to goto the second page beforehand.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
V

Victor Dong

Hi Helmut,
In fact I already move to next page, because I added more shapes on the
second page, text boxes, circle boxes etc.

Thanks
 
V

Victor Dong

Hi Helmut,
Here is code to moving to next page

Public Function MoveToNextPage() As Boolean

MoveToNextPage = False

On Error GoTo ErrHandler

With m_Document
'Insert a new page
Set m_Range = .Paragraphs(.Paragraphs.Count).Range
m_Range.Collapse Direction:=wdCollapseEnd
m_Range.InsertBreak Type:=wdPageBreak

'Move to new page
Set m_Range = .Paragraphs(.Paragraphs.Count).Range
m_Range.Collapse Direction:=wdCollapseEnd
m_Range.Select
m_Range.Font.Size = 1
End With

m_Word.Windows(m_Word.Windows.Count).View.SeekView = wdSeekMainDocument

MoveToNextPage = True

Exit Function

ErrHandler:
GeneralErrorHandler 0, "Error occurred when moving to new page. " _
& Err.Description
End Function
 
H

Helmut Weber

Hi Victor,

I don't know.
Seems all much too complicated for me.
Don't know what all that paragraph counting is good for.

A page break is part of a paragraph,
as anything in Word.
If you insert a pagebreak and select the paragraph
containing that pagebreak, the paragraph expands
over two pages.

What is SeekView = wdSeekMainDocument doing?

Insert a new page at the end of the doc.
Insert a picture there.

Like this:

Sub Macro6()
ActiveDocument.Range.Characters.Last.InsertBreak wdPageBreak
ActiveDocument.Range.Characters.Last.Select
selection.Collapse
selection.InlineShapes.AddPicture FileName:= _
"C:\Pic\Bluehills.jpg"
End Sub

I don't now better.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
V

Victor Dong

Hi Helmut,

The thing is real weird.

In the first page I insert a lot of shapes and write a couple paragraphs. It
works well, after move to next page, I still can insert a lot of shapes, such
as text box, circle shape, they all be put the location that I hope, I put
unique ID to each shape, later on I open this word file, I can read back all
these shape location according to ID and do whatever I want to do. Only the
picture is different. I doubt MS word handle regular shape and picture in
different way. If I was wrong, why the others shape work well and only
picture failed in the second page. Funny thing is that in Office 2000 + SP3,
after I insert picture in the second page, they were put on the first page
and all first page shapes were shifted down, but in Office 2003, the first
page shapes location were not changed, only the second page picture were put
on.
That's why I try .Shapes.AddPicture, and .InlineShapes.AddPicture both
methods.

BTW, below is minor thing, please ignore it
m_Word.Windows(m_Word.Windows.Count).View.SeekView = wdSeekMainDocument

I do not have any new version word that can be used now, so I have to be here.

Anyway I real appreciate your response.

Have a nice weekend.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top