By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

How to execute mspaint and open a file

P: 19
I can execute mspaint using VBA but I have not been successful trying to open a .jpg image file. This command works to execute mspaint but I do not know how to excute and bring up a file at the same time. I am using Access 2007.

Dim retVal
retVal = Shell("c:\windows\system32\mspaint.exe", vbMaximizedFocus)
Sep 22 '08 #1
Share this Question
Share on Google+
8 Replies


aas4mis
P: 97
I can execute mspaint using VBA but I have not been successful trying to open a .jpg image file. This command works to execute mspaint but I do not know how to excute and bring up a file at the same time. I am using Access 2007.

Dim retVal
retVal = Shell("c:\windows\system32\mspaint.exe", vbMaximizedFocus)
All you need is the file location after your command.
Expand|Select|Wrap|Line Numbers
  1. Dim retVal
  2. retVal = Shell("c:\windows\system32\mspaint.exe c:\image.png", vbMaximizedFocus)
Sep 22 '08 #2

Megalog
Expert 100+
P: 378
Are you dynamically opening different files with paint, or are you just trying to open one exact jpg?
If the image isnt going to change, then you could code it in like shown above. But, if the path has any spaces in it you will need to put the entire filepath in quotes.

If you're going to dynamically pass the file path to it, then use the following:
Expand|Select|Wrap|Line Numbers
  1. Dim retVal
  2. Dim strImgPath As String
  3. retVal = Shell("c:\windows\system32\mspaint.exe " & """" & strImgPath & _
  4.     """", vbMaximizedFocus)
That will ensure the proper quotes are inserted around the filepath.
Sep 22 '08 #3

P: 19
Appreciate the quick response. Still did not work. Paint comes up - but no image. Here is what I keyed:

Dim retVal
retVal = Shell("c:\windows\system32\mspaint.exe c:\CoronerDrawing.jpg", vbMaximizedFocus)

I made the path simple and can double click this file and it comes right up in Paint.
Sep 22 '08 #4

P: 19
Sorry guys - you were right. To the head of the class. I forgot I had used a macro instead of an event procedure. I am a little embarssed about that.
Thanks. It worked.

Here is the final work.

Dim retVal
Dim strImgPath As String
'
strImgPath = "c:\CoronerDrawing.jpg"

retVal = Shell("c:\windows\system32\mspaint.exe " & """" & strImgPath & _
"""", vbMaximizedFocus)
'
Sep 22 '08 #5

Megalog
Expert 100+
P: 378
Glad to help!
And your database already sounds way more interesting than the ones I work on.. with coroner drawings, etc =)
Sep 22 '08 #6

P: 19
I am writing a system for our Coroner. This is the first complete system I have done using Access and VBA. I am truly a Cobol guy :)
Sep 22 '08 #7

missinglinq
Expert 2.5K+
P: 3,532
I am writing a system for our Coroner. This is the first complete system I have done using Access and VBA. I am truly a Cobol guy
Well, that's really appropriate! After all, Cobol really is a "dead" language!

Linq ;0)>

P.S. Sorry, but you just make it so darn easy to be cheesy!
Sep 22 '08 #8

P: 1
"Whoo-hoo-hoo, look who knows so much. It just so happens that your friend here is only MOSTLY dead. There's a big difference between mostly dead and all dead. Mostly dead is slightly alive."
Miracle Max


@missinglinq
Mar 15 '17 #9

Post your reply

Sign in to post your reply or Sign up for a free account.