Solved

Put a picture in Word 97 Table with vb

Posted on 2001-07-14
11
215 Views
Last Modified: 2007-12-19
I am using vb6 with word 97 or 2000  (user's choice)
My software needs to replace a text placeholder in a Word document with a
picture from a .jpg file and, of course, should work for all reasonable
versions of Word.
Ideally, for page layout convenience, the placeholder ("#PICTUREHERE#") is
in a Table (1 row, 1 column).

The subroutine below works fine with Word 2000 but, in Word 97 the picture
finishes outside the table (before it) even if I put a space before the
placeholder. I have tried putting the picture in the Clipboard and
Selection.Paste with the same result in Word 97.

Is there any way I can ensure that Word 97 puts a picture into a Table?

The essence of my MergePic Subroutine is as follows.

Sub MergePic(Appw As Object, picfilename$, PlaceHolder As String)
'   Appw is a Word Object,
'   PlaceHolder is something like "#PLACEHOLDER#"
'   picfilename$ is a .jpg file normally

Appw.Selection.HomeKey Unit:=wdStory
Appw.Selection.Find.ClearFormatting
With Appw.Selection
    .Find.Text = PlaceHolder
    .Find.Replacement.Text = ""
    .Find.Forward = True
    .Find.Wrap = wdFindContinue
    .Find.Format = False
    .Find.MatchCase = False
    .Find.MatchWholeWord = False
    .Find.MatchWildcards = False
    .Find.MatchSoundsLike = False
    .Find.MatchAllWordForms = False
    .Find.Execute
End With

Do While Appw.Selection.Find.Found
    'replace text with blank
    Appw.ActiveDocument.Shapes.AddPicture Anchor:=Appw.Selection.Range, _
        FileName:=picfilename$, LinkToFile:=False, SaveWithDocument:=True
    Appw.Selection.TypeText Text:=" "
    Appw.Selection.Find.Execute
Loop
End Sub

I would greatly appreciate help from somewhere

Roy Low





0
Comment
Question by:roylow
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 13

Expert Comment

by:cri
ID: 6283430
With which Service Release of Office 97 do you test your code ? Looks like you need SR-1:

http://support.microsoft.com/support/kb/articles/Q172/5/90.ASP
 
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 6283507
You cannot place a picture that is "float over text" into a table cell.

It must be:

97:  float-over-text property removed using Format-Picture, Position tab

2000: text-wrap setting is "in line with text" using Format-Picture, Layout
0
 
LVL 13

Expert Comment

by:cri
ID: 6283930
Dreamboat, the default of Word 97 _SR-1_ is with cleared float over text.

See also http://support.microsoft.com/support/kb/articles/Q170/5/64.ASP
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 22

Expert Comment

by:Dreamboat
ID: 6284252
Did you test that on your PC, cri? Because if you've never used insert-picture before, I think the default (after install) is float over text, but next time, it uses the previous method, whether float over text or not.
0
 

Author Comment

by:roylow
ID: 6284262
I am using SR 4
Dreamboat, your comment re changing default explains why all this is not consistent, sometimes works and sometimes not.
How do I force W 97 to put picture if there is one?a table if the
0
 

Author Comment

by:roylow
ID: 6284265
Finger trouble, last message should read
I am using SR 4
Dreamboat, your comment re changing default explains why all this is not consistent, sometimes works
and sometimes not.
How do I force W 97 to put picture in a table if there is one?
0
 
LVL 22

Accepted Solution

by:
Dreamboat earned 200 total points
ID: 6284270
Get on a Word 97 PC. Record a macro while you insert a picture and remove (or add and then remove) the float over text option on the picture. This should give you the code you need to insert to make your pix NOT be float over text, but I'm not sure what the command is because I don't have 97. I will be at my work pc tomorrow. Perhaps I can get it for you then. I do not think we have to distinguish between 97 and 2000, but we may, who knows?
0
 
LVL 13

Expert Comment

by:cri
ID: 6284670
Dreamboat, yes I tested it. And it should be the default as I never done that.

roylow: SR-4 ? There is no reference for Office 97. AFAIK there is SR-2, then came the "Leap-Year Fix" in end of 1999. However I do not know how this one is listed in Help|About, our IT department does not think it necessary to install this. But that is another story.
0
 

Author Comment

by:roylow
ID: 6288501
I have tried lots!
VBA from Word 97 uses
ActiveDocument.InlineShapes.AddPicture Range:=Selection.Range, _
FileName:=picfilename$, LinkToFile:=False, SaveWithDocument:=True

and works fine

BUT

In my VB app, the line:

Appw.ActiveDocument.InlineShapes.AddPicture Range:=Selection.Range, _
FileName:=picfilename$, LinkToFile:=False, SaveWithDocument:=True

does not accept the command

I have also tried "ConvertToInlineShape" (of something similar) with no success either.

The present "solution" is to tell any user with Word 97 not to use Tables.

I really would like a piece of vb code that works with either though detecting which version is easily done if req.
0
 
LVL 13

Expert Comment

by:cri
ID: 6291330
You sure you have the same selection active ? And, long shot, do you use Option Explicit ? picfiIename$ and picfilename$ look the same but are not.
0
 

Expert Comment

by:costello
ID: 6415693
If no objections are made in the next 5 days, I will PAQ this question for 0 points, and refund those points.

costello
Community Support Moderator @ Experts-Exchange

P.S. This post is made as part of the general effort to clean up this topic area, meaning, looping through all the open questions with no activity since 21 days.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Perhaps more familiar to developers who primarily use VBScript than to developers who tend to work only with Microsoft Office and Visual Basic for Applications (VBA), the Dictionary is a powerful and versatile class, and is useful …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question