PDA

View Full Version : Solved: Refresh Image in macro



SilverSN95
03-11-2010, 11:00 AM
Hi,
There is probably a very simple solution for this, but I have been looking everywhere and cant seem to find what I need...

I have this macro I am using in a word doc, so users can insert a signature image at the bottom of the document by clicking on an image field.

Private Sub Image1_Click()
Application.ScreenUpdating = False
Dim fname As String
' Display the Open dialog box.
fname = WordApplicationGetOpenFileName("*.*", True, True)

If fname <> "False" Then

On Error Resume Next
Image1.Picture = LoadPicture(fname)
If Err.Number <> 0 Then
MsgBox "Error loading file: " + fname
End If

' ***Refresh.

End If

Application.ScreenUpdating = True
End Sub
Where WordApplicationGetOpenFileName is basically GetOpenFileName for word. The image does load into the image space, but only becomes visible after resizing the window. What to I need to add in the macro so users don't think the image didn't load?

Also, in print preview, I can still see the image container around the loaded image, can I either hide this from printing, or resize the area to match the image?

Thanks!

macropod
03-11-2010, 01:34 PM
Hi SilverSN95,

Try inserting:
Application.ScreenRefresh
where you have the '' ***Refresh.' comment.

SilverSN95
03-11-2010, 02:32 PM
Thanks macro, but I should have said I tried this one already, before and after ScreenUpdating = True.
The refresh must be specific to the object (I'm not really sure what it is, a userform?).

macropod
03-11-2010, 03:56 PM
Hi SilverSN95,

Are you inserting the image onto the userform, or into the document? You also mention a field - is that a Word field or just something you're calling a field? If it's a Word field, what kind of field?

fumei
03-12-2010, 09:43 AM
What version are you using?

WordApplicationGetOpenFileName

This fails for me.

SilverSN95
03-12-2010, 08:12 PM
Thanks for the replies, I'll upload the test file on Tuesday when I'm at work so you can see what I mean.
WordApplicationGetOpenFileName is the name of a sub I found online that does the equivalent of getopenfilename but for Word. The doc will have that sub defined as well once I get to post it.

SilverSN95
03-16-2010, 09:49 AM
OK, here is the document I was using to test with. The idea is that this image would be at the bottom of a form (which will be protected), but users can click, insert their signature image and then print/save the form normally.

Again, I would like the image to refresh without having to re-size the window, and have the clickable form area either re-size to the image inside it, or be hidden from printing.

Thanks again.

fumei
03-16-2010, 11:27 AM
Not quite following.

"have the clickable form area either re-size to the image inside it"

To have the image control resize to the image, set its AutoSize property to TRUE.

"or be hidden from printing"

Why would you want to hide it if it is a signature image? I would think the whole point is to have it there for printing.

SilverSN95
03-16-2010, 11:48 AM
Thanks Fumei, I meant hide the container (I'm not sure what these things are called) but not the actual image.
As you recommended, setting AutoSize to true not only resizes the container, but by adding this line the image is also refreshes it as well. Looks like this took care of both my issues!

I'm going to mark as solved, although I will be playing with the image a little more to make sure its working correctly.

fumei
03-16-2010, 11:55 AM
"I will be playing with the image a little more to make sure its working correctly."

Oh, I would think that is a very good idea.

"I meant hide the container (I'm not sure what these things are called) but not the actual image."

Well, I image the "container" is the ActiveX image control itself. If you want its border to disappear, change its Border Color to Window Background. Or change BorderStyle to fmBorderStyleNone ( = 0).

fhimage
06-20-2013, 09:07 PM
same to me, can't figure out what's wrong

fumei
06-22-2013, 11:39 PM
"same to me" WHAT is the same. If you can not figure out what is wrong I doubt anyone here can either, as you say nothing about anything. If you have a problem please actually describe that problem.