Solved

Put a picture in Word 97 Table with vb

Posted on 2001-07-14
11
213 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macbook MS Office installer missing 11 82
Excel totals by filter - Automated 4 36
Copying and pasting pictures from Excel 2 40
Microsoft Edge, Outlook OWA 7 35
In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

943 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

10 Experts available now in Live!

Get 1:1 Help Now