[RESOLVED] automating ms Paint???
Is there a way to automate MS Paint tasks from Word. I know that you can execute an external application from VBA using SHELL() command, but is it also possible that you take the input D from Word to an external App, modify it and use the output D' back in your Word document.
Concretely, I want to take a graphic from my Word file, add some text on it, save it as graphic and replace the original graphic by the new one.
The main problem is how to execute an external app to edit then the image automatically...
I don't know if it is possible at all, do anyone has an idea, I appreciate it.
cheers
Re: automating ms Paint???
Yes, its possible but you will can only do so much as its up to the user to save the file and draw the changes.
Just Shell mspaint.exe with the full path. If you are using this app on other systems then you will want to dynamically get the path to paint.
The issue will be that you will need to know when the user is done modifying the image so you can refresh the link to th eimage.
Re: automating ms Paint???
Hey there. I recommend picking up a book called the Access Cookbook if you're ever looking for something to read. It had a lot of useful functions, and here is one of them. This will shell a program and pause execution until the program terminates. After that, just check to see if the file was updated and do what you need to do.
VB Code:
Sub RunAppWait(strCommand As String, intMode As VbAppWinStyle)
' Run an application, waiting for its completion
' before returning to the caller.
Dim hInstance As Long
Dim hProcess As Long
Dim lngRetval As Long
Dim lngExitCode As Long
On Error GoTo ahtRunAppWait_Err
' Start up the application.
hInstance = Shell(strCommand, intMode)
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or SYNCHRONIZE, _
True, hInstance)
Do
' Attempt to retrieve the exit code, which will
' not exist until the application has quit.
lngRetval = GetExitCodeProcess(hProcess, lngExitCode)
DoEvents
Loop Until lngExitCode <> STILL_ACTIVE
ahtRunAppWait_Exit:
Exit Sub
ahtRunAppWait_Err:
Select Case Err.Number
Case glrcErrFileNotFound
MsgBox "Unable to find '" & strCommand & "'"
Case Else
MsgBox Err.Description
End Select
Resume ahtRunAppWait_Exit
End Sub
Re: automating ms Paint???
I forgot to include the headers at the top of the module.
VB Code:
Const PROCESS_QUERY_INFORMATION = &H400
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFFFFFF
Const STILL_ACTIVE = &H103&
Const glrcErrFileNotFound = 53
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Re: automating ms Paint???
thanx Dmar I will try it out...