saving an image in the document

B

Bruce Baker

H

I'm using VB and want to save a linked gif in the document - e.g. the same as pressing ctrl-shift-f9

How do I do this programatically

Thank
Bruc
 
P

Peter Hewett

Hi Bruce

You don't show that code your using, but if you use something like this it'll
do what you want:

' Insert any image you have available
Selection.InlineShapes.AddPicture FileName:="C:\Temp\Bath.jpg", _
LinkToFile:=False, SaveWithDocument:=True

The above is a VBA version but the key is "SaveWithDocument:=True".

HTH + Cheers - Peter
 
B

Bruce Baker

Sorry, I should have been more specific

I am creating an HTML document in my VB app (via XML / XSL) which has a .gif in it.

I then need to convert the HTML doc to a word doc. Plan on opening it and then saving it as a word document (.doc).

I'm still at a bit of a loss as to what to do

Thank
Bruce
 
P

Peter Hewett

Hi Bruce

Likewise it's tricky as I can't replicate what you're doing. However, on the
assumption your codes at the stage where it can generate the HTML and start
Word and open the HTML document all we need to do is replicate Ctrl+Shift+F9
(Unlink Field) for the field(s) than contain a picture. The logic for this is
pretty strightfoward once we confirm that the picture is loaded through an
INCLUDEPICTURE field. To check which field Words using just click on the
picture and press Shift+F9 to toggle reveal codes.

Cheers - Peter
 
B

Bruce Baker

Hi Peter

Thanks for your help. Yes. I'm creating the HTML fine (pretty happy with that !)

I've done as you've asked and yes, it is included via includepicture

The exact field code is INCLUDEPICTURE "../../img/banner-logo-t.gif"

Thanks
Bruce
 
P

Peter Hewett

Hi Bruce

Here's some code that will unlink just the Includepicture fields:

Sub UnlinkIncludepictureFields()
Dim rngStory As Word.Range
Dim lngIndex As Long

' Iterate through all story types
For Each rngStory In ActiveDocument.StoryRanges

Do Until rngStory Is Nothing

' Do this backwards as we are using the fields
' index and deleteing fields from the same collection at
' the same time
For lngIndex = rngStory.Fields.Count To 1 Step -1
With rngStory.Fields(lngIndex)
If .Type = wdFieldIncludePicture Then
.Unlink
End If
End With
Next

' There may be linked stories so make sure we get them as well
Set rngStory = rngStory.NextStoryRange
Loop
Next
End Sub

When I develop VB interop applications I often try things out in the VBA
environment and then port it to the VB environment. As you can see the above
is VBA code, you'll need to prefix the "ActiveDocument" object with whatever
variable you're using for your Word Application object.

HTH + Cheers - Peter
 
B

Bruce Baker

Fantastic - thanks - I've got one more question but I'll create a new thread for that one

Cheer
Bruce
 

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