Copying Image

V

vbaNOOB

Hi

I'm working on a task that copying all image a doc to another.
I got stuck when I meet textbox.

All the image after the textbox actually go into the textbox !!!
There different types of image in doc, inshape, shape (texbox, line)
I found a sth that can exist from a textbox while the cusur is inside the
txtbox
but How do i if the cusur is inside the txtbox or not?

Thinking I am using:

for each shapes
select the shape
selection.cut
anotherdoc.activite
selection.paste
originaldoc.activite
next
 
J

Jean-Guy Marcil

vbaNOOB was telling us:
vbaNOOB nous racontait que :
Hi

I'm working on a task that copying all image a doc to another.
I got stuck when I meet textbox.

All the image after the textbox actually go into the textbox !!!
There different types of image in doc, inshape, shape (texbox, line)
I found a sth that can exist from a textbox while the cusur is inside
the txtbox
but How do i if the cusur is inside the txtbox or not?

Thinking I am using:

for each shapes
select the shape
selection.cut
anotherdoc.activite
selection.paste
originaldoc.activite
next

Use the Selection object as little as possible and do use objects as much as
possible, like range, documents, shapes, etc.

Try this:

'_______________________________________
Option Explicit

'_______________________________________
Public Sub BatchSaveAllAsDoc()

Dim shpCopy As Shape
Dim docSource As Document
Dim docTarget As Document
Dim rgeStart As Range
Dim rgeTarget As Range

Set rgeStart = Selection.Range
Set docSource = ActiveDocument
Set docTarget = Documents.Add
Set rgeTarget = docTarget.Range
rgeTarget.Collapse wdCollapseEnd

For Each shpCopy In docSource.Shapes
shpCopy.Select
Selection.Copy
With rgeTarget
.Paste
'If you want all pasted shapes to be anchored to the first paragraph
_
then remove or comment out the following two lines
.InsertParagraphAfter
.Collapse wdCollapseEnd
End With
Next

rgeStart.Select

End Sub
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
V

vbaNOOB

WOW, It is great.
I have written 3 pages of code about copying image, but it did not work
out....

Another question, now the image is paste "together" in 1 page.
Is that a way that all images in the same page from the source doc are
pasted in 1 page of the tagart doc.

Sorry for my English

The example:
Source Doc-
page 1 have 3 images
page 2 no image
page 3 4 images

After running the VBA
Tagart Doc-
page 1 : all 3 images from source doc page 1
page 2 : all 4 images from source doc page 3

Many thanks
 
J

Jean-Guy Marcil

vbaNOOB was telling us:
vbaNOOB nous racontait que :
WOW, It is great.
I have written 3 pages of code about copying image, but it did not
work out....

Another question, now the image is paste "together" in 1 page.
Is that a way that all images in the same page from the source doc are
pasted in 1 page of the tagart doc.

Sorry for my English

The example:
Source Doc-
page 1 have 3 images
page 2 no image
page 3 4 images

After running the VBA
Tagart Doc-
page 1 : all 3 images from source doc page 1
page 2 : all 4 images from source doc page 3

Many thanks

This will be a little difficult.
The problem is that the shape collection is indexed according to the order
in which they were created, not the order in which they appear on the
document. So, this means that iterating the shapes will go from the oldest
to the newest.

The only way around that I can see is to add complicated code to do the
following:
Once you have selected a shape, use:
Selection.Information(wdActiveEndPageNumber)
to get the page number
Before pasting in the target document, go to the same page number (using
"docTarget.GoTo"), but first make sure that this page number exists, if it
does not, use "rgeTarget.InsertBreak" to add as many page as necessary to
get tot he same page number. "rgeTarget" will need to be redefined at each
pass with a "Set" statement.
When you are done, scan the target document to remove empty pages, i.e.
pages containing nothing but a ¶, or Chr(13).

There maybe an easier way, but right now this is all I can some up with..

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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