Solved

Put a picture in Word 97 Table with vb

Posted on 2001-07-14
11
217 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:Roy Low
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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:Roy Low
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:Roy Low
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:Roy Low
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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

630 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