How to import all files into a document which where former just links?

P

Peter Müller

I have to write a subroutine doing the same as:

1. Click Edit -> Links...
2. Select all links
3. Select "Save picture in document" and click "OK" afterwards

The macro recoder doesn't generate code. Neither the Word 2003 version
nor the Word 2007 version.
 
G

Graham Mayor

Word 2003 and 2007 handle graphics differently from one another. The
following should work for Word 2003 document format.

Dim oField As Field
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldIncludePicture Then
oField.Unlink
End If
Next oField

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
P

Peter Müller

Graham said:
Word 2003 and 2007 handle graphics differently from one another. The
following should work for Word 2003 document format.

Dim oField As Field
For Each oField In ActiveDocument.Fields
If oField.Type = wdFieldIncludePicture Then
oField.Unlink
End If
Next oField

When I tried to test the code I got a document where instead of the
images only empty frames occur. Now it seems to work and I have no clue
what was different on Friday.

How shall the code look like when using Office 2007? And how can I
create a version which works whith both Office 2003 and Office 2007?
 
G

Graham Mayor

doc format and docx format handle graphics differently and I am not sure
whether it is possible to unlink the images in docx format in this way.
Unless someone knows better and comes up with an alternative solution, one
Heath Robinson method would be to save the document as doc format before
unlinking and then resave as docx. This might be a problem if you have used
some of the features unique to Word 2007 document format. The following does
that:

Dim oField As Field
Dim fName As String, fNew As String
With ActiveDocument
If .Saved = False Then
.Save
End If
fName = .FullName
fNew = Left(ActiveDocument.FullName, _
InStrRev(.FullName, ".")) & "doc"
.SaveAs FileName:=fNew, FileFormat:=wdFormatDocument97
For Each oField In .Fields
If oField.Type = wdFieldIncludePicture Then
oField.Unlink
End If
Next oField
.SaveAs FileName:=fName, FileFormat:=wdFormatXMLDocument
End With
Kill fNew


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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