Solved

Put a picture in Word 97 Table with vb

Posted on 2001-07-14
11
211 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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.
My experience with Windows 10 over a one year period and suggestions for smooth operation
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now