Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Put a picture in Word 97 Table with vb

Posted on 2001-07-14
11
Medium Priority
?
220 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 800 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Quickbooks hosting can do wonders to your enterprise but considering the points elaborated in the article which will help you to better analyze the outcomes. So scan your business, its needs and then move to the new world of limitless benefits.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

972 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