Need help with odd behavior

S

Steve

I am using a macro that inserts a picture in a table cell
using:
Selection.InlineShapes.AddPicture Filename:=variable_name,
LinkToFile:=False, SaveWithDocument:=True

If I do a File->New from Word and create a document based on
this template it works great. However, if I save the created
document and reopen it, things don't work right. If I run the
macro now, instead of a picture being inserted I just see the
outline of a box where the picture should be.

Can anyone help me with this?

Thanks,
Steve
 
D

Dave Lett

Hi Steve,

After you save and reopen the document, check your view settings to make sure that Picture Placeholders is deselected. On the Tools menu, click Options. In the Options window, activate the View tab, and in the Show area, be sure to deselect Picture placeholders.

If this doesn't solve your problem, then the issue might be with "variable_name"; first make sure that the file exists in that directory. Also, you might want to make sure that "variable_name" is an explict path rather than an relative path.

HTH,
Dave
 
S

Steve

=?Utf-8?B?RGF2ZSBMZXR0?= <[email protected]>
wrote in
Hi Steve,

After you save and reopen the document, check your view settings to
make sure that Picture Placeholders is deselected. On the Tools menu,
click Options. In the Options window, activate the View tab, and in
the Show area, be sure to deselect Picture placeholders.

If this doesn't solve your problem, then the issue might be with
"variable_name"; first make sure that the file exists in that
directory. Also, you might want to make sure that "variable_name" is
an explict path rather than an relative path.

HTH,
Dave

I wish this had worked but no luck. Picture placeholders are
not selected. I also added code to pop up a msgbox with the
jpg file name that was stored in the variable and it looks
fine.

It seems that the code works fine on the creation of a new
document, but after the document is saved and reopened it
doesn't work.

Any more ideas would be greatly appreciated.

Steve
 
D

Dave Lett

Hi Steve

Hmm, I'm not sure. Is the path to the file long, or does it have spaces in the names of the folder(s)? If so, you might need to use double backslashes for each path separator, as in

C:\My Long Folder Name\My Long Folder Name2\My Long Folder Name3\myPic.jpg
might need to be
C:\\My Long Folder Name\\My Long Folder Name2\\My Long Folder Name3\\myPic.jpg

If this doesn't solve your problem is there _any_ other information other tha

1) create a new document, code work
2) save the newly created document, close document, reopen, and code does not work

HTH
Dave
 
S

Steve

=?Utf-8?B?RGF2ZSBMZXR0?= <[email protected]>
wrote in
Hi Steve,

Hmm, I'm not sure. Is the path to the file long, or does it have
spaces in the names of the folder(s)? If so, you might need to use
double backslashes for each path separator, as in

C:\My Long Folder Name\My Long Folder Name2\My Long Folder
Name3\myPic.jpg might need to be
C:\\My Long Folder Name\\My Long Folder Name2\\My Long Folder
Name3\\myPic.jpg

If this doesn't solve your problem is there _any_ other information
other than

1) create a new document, code works
2) save the newly created document, close document, reopen, and code
does not work.

HTH,
Dave

The problem is as simple as 1) and 2) you listed. A new
document inherits the code from the template and works. I
save and reopen the document and the code behaves differently.

The directory I'm using is C:\Temp so a long path should not
be the issue.

Help!
 
P

Peter Hewett

Hi Steve

Post the code that causing the problem otherwise everyone's just fumbling in
the dark and we're all just guessing at what's going on.

Cheers - Peter
 
S

Steve

Hi Steve

Post the code that causing the problem otherwise everyone's just
fumbling in the dark and we're all just guessing at what's going on.

Cheers - Peter

Okay - here we go.

The template has a table with 4 cells and here is the code:

Sub DoImage()

'Change to proper directory
ChDir ("C:\Temp")


'Loop while waiting on image to arrive in the temp
directory

Do While temp$ = ""
Sleep
temp$ = Dir("*.jpg")
Loop

'We're out of the loop so image must be there - insert it
Selection.InlineShapes.AddPicture FileName:=temp$ _
, LinkToFile:=False, SaveWithDocument:=True

End Sub

Sub Sleep()
'

PauseTime = 1 ' Set duration of 1 second.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop

End Sub

After this template is created and saved:
1. File -> New -> Document, choose the template you created as
the basis for the new document.
2. Place the cursor in one of the table cells
3. Start the macro
4. Paste a jpg into the \temp directory
5. The photo will appear in the cell
6. This works as expected

Now try this:
1. File -> New Document, again based on the template
2. Save and close the new document
3. Reopen the document
4. Postion cursor in a table cell
5. Start the macro
6. Paste jpg into \temp
7. Nothing shows in the cell until you click it and you will
see just a square box, an outline I guess.
8. Why is the photo not showing?

Hope this helps solve the issue. Thanks to all for researching
this.

Steve
 
P

Peter Hewett

Hi Steve

From Words menu Tools/Options/View/Picture Placeholders make sure this is
unchecked. Check it after opening the document that does not display the
pictures.

If that's got nothing to do with it replace your macro with something like
the following:

Sub DoImage()
' Insert any image you have available
Selection.InlineShapes.AddPicture FileName:="C:\Bath.jpg", _
LinkToFile:=False, SaveWithDocument:=True
End Sub

You'll need to replace the filename in the above example. Use this as you
would your macro and see if you get the same results. The idea here is to
determine what if anything the code has to do with the problem.

I can't find any documentation on temp$, but I'm assuming that's not the
cause of the problem.

Also, if you right click on the picture outline do you get the "Edit
picture" option on the context menu.

Cheers - Peter
 
S

Steve

Hi Steve

From Words menu Tools/Options/View/Picture Placeholders make sure this
is unchecked. Check it after opening the document that does not
display the pictures.

If that's got nothing to do with it replace your macro with something
like the following:

Sub DoImage()
' Insert any image you have available
Selection.InlineShapes.AddPicture FileName:="C: \Bath.jpg", _
LinkToFile:=False, SaveWithDocument:=True
End Sub

You'll need to replace the filename in the above example. Use this as
you would your macro and see if you get the same results. The idea
here is to determine what if anything the code has to do with the
problem.

I can't find any documentation on temp$, but I'm assuming that's not
the cause of the problem.

Also, if you right click on the picture outline do you get the "Edit
picture" option on the context menu.

Cheers - Peter

Finally fixed it. Thanks for all the help.

Had to concatenate two strings to create an absolute path.
"C:\Temp" & name_of_jpg_file & ""

Whew!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top