Results 1 to 5 of 5

Thread: [RESOLVED] automating ms Paint???

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    34

    Resolved [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

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    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:
    1. Sub RunAppWait(strCommand As String, intMode As VbAppWinStyle)
    2.    ' Run an application, waiting for its completion
    3.    ' before returning to the caller.
    4.  
    5.    Dim hInstance As Long
    6.    Dim hProcess As Long
    7.    Dim lngRetval As Long
    8.    Dim lngExitCode As Long
    9.  
    10.    On Error GoTo ahtRunAppWait_Err
    11.    ' Start up the application.
    12.    hInstance = Shell(strCommand, intMode)
    13.    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or SYNCHRONIZE, _
    14.       True, hInstance)
    15.    Do
    16.       ' Attempt to retrieve the exit code, which will
    17.       ' not exist until the application has quit.
    18.       lngRetval = GetExitCodeProcess(hProcess, lngExitCode)
    19.       DoEvents
    20.    Loop Until lngExitCode <> STILL_ACTIVE
    21.    
    22. ahtRunAppWait_Exit:
    23.    Exit Sub
    24.  
    25. ahtRunAppWait_Err:
    26.    Select Case Err.Number
    27.       Case glrcErrFileNotFound
    28.          MsgBox "Unable to find '" & strCommand & "'"
    29.       Case Else
    30.          MsgBox Err.Description
    31.    End Select
    32.    Resume ahtRunAppWait_Exit
    33. End Sub

  4. #4
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: automating ms Paint???

    I forgot to include the headers at the top of the module.

    VB Code:
    1. Const PROCESS_QUERY_INFORMATION = &H400
    2. Const SYNCHRONIZE = &H100000
    3. Const INFINITE = &HFFFFFFFF
    4.  
    5. Const STILL_ACTIVE = &H103&
    6.  
    7. Const glrcErrFileNotFound = 53
    8.  
    9. Private Declare Function OpenProcess Lib "kernel32" _
    10.  (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    11. Private Declare Function GetExitCodeProcess Lib "kernel32" _
    12.  (ByVal hProcess As Long, lpExitCode As Long) As Long

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2006
    Posts
    34

    Re: automating ms Paint???

    thanx Dmar I will try it out...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width