Page 1 of 4 1234 LastLast
Results 1 to 15 of 47
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,185

    Opening All Files With ms paint

    Hi Guy's I am trying to open jpg files in ms paint, i am unsure if paint would require specific file names to open whereas I am trying to force it to open all files regardless of qty



    note we would never require hundreds of files which i would think would cause issues, perhaps 10 or under

    I am trying to open them in ms paint to resize them for emailing, the debug i am getting is Runtime error 53 file not found

    Can i force it to open all files in the folder or do you think it's not the file name that it cant find, i currently have 2 jpg files in the folder just to test it

    I haven't pasted full code as its working apart from opening in paint

    Code:
    Set fso = CreateObject("Scripting.FileSystemObject")Set objFiles = fso.GetFolder(srcPath).Files
        imgQty = objFiles.Count
    
    
        srcFile = Dir(srcPath & "*.*")
        x = 1
        Do Until srcFile = vbNullString
           FileCopy srcPath & srcFile, imgPath & srcFile
            srcFile = Dir
            x = x + 1
        Loop
        
        For Each objFiles In fso.GetFolder(srcPath).Files
            objFiles.Delete
            Next
            
        If MsgBox("Sucessfully Moved Your " & imgQty & " " & "Of Images Form SD Card To PC" & vbNewLine & vbNewLine & _
            "Do You Want To Open " & imgQty & " " & "In Paint To Resize To 10% ?", vbQ + vbYesNo, "OPEN IN PAINT") = vbNo Then
            Exit Sub
            Else
        Shell "C:\Windows\System32\mspaint.exe" & imgPath & "*.jpg"
        End If
        
        Debug.Print imgPath & "*.jpg"

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Still not debugging your code I see?
    You have NO SPACE after your exe ?

    Does MSPaint actually open multiple files.? Have you tried in a command window?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I don't think your quotes are right but I haven't figured out how to fix that. This was a solution for passing a switch to open Edge with a specific profile:
    """C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"" --profile-Directory=""Profile 1"""

    Maybe you or someone else can figure it out based on that. My brain seems to be fogged at the moment, due to lack of coffee, so I'm going to take care of that now.
    EDIT - I doubt you'll be able to open multiple files like that since this technique seems to replicate what desktop shortcuts do. Likely you'll have to loop, but happy to learn if I'm wrong about that.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    After trial and mostly error I could get this to open the single file
    Code:
    Shell ("C:\Windows\System32\mspaint.exe C:\Users\Micron\Access\Icons\Transportation\ROCKET.bmp")
    However, I could not get Shell(str) to work even though debug.print str showed exactly the same string. I thought, what if I use Eval on the string?
    Obviously coffee is the magic elixir because this modification to my Edge profile code works (see notes at end)
    Code:
    Function testEdgeProfile()
    Dim str As String, imgPath As String
    imgPath = " C:\Users\Micron\Access\Icons\Transportation\ROCKET.bmp" & """"
    str = """C:\Windows\System32\mspaint.exe" & imgPath
    'Debug.Print imgPath
    'Debug.Print str
    Shell (Eval(str))
    
    End Function
    Note: there are no spaces in the path OR in the file path string. If you have spaces in your folder or file names and that causes issues with that code, then shame on whoever did that and good luck figuring that out. Also, I didn't test with other file types nor did I attempt to open multiple files at the same time. I'll leave those problems to others.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by DMT Dave View Post
    Hi Guy's I am trying to open jpg files in ms paint, i am unsure if paint would require specific file names to open whereas I am trying to force it to open all files regardless of qty
    From my testing it looks like ms paint only takes one argument, and using something like *.jpg only opens the first file. You will have to loop through your directory and open each file individually


    I am trying to open them in ms paint to resize them for emailing
    Can you elaborate on what/how you're doing this? This could probably be automated as well.


    Finally, as others have mentioned your syntax for the shell command is off. It's a good idea to enclose any paths or filenames within shell commands in quotation marks. Otherwise, generally speaking, a shell command's argument parser will split everything by any spaces. If there are any spaces in any directory names or file names it won't be interpreted correctly.

    For example:
    Code:
    Shell "C:\Windows\System32\mspaint.exe C:\My Picture.jpg"
    would send the following to the command line:
    Code:
    C:\Windows\System32\mspaint.exe C:\My Picture.jpg
    Which would get split by spaces like this
    Code:
    C:\Windows\System32\mspaint.exe
    C:\My
    Picture.jpg
    C:\My isn't a valid path so the command C:\Windows\System32\mspaint.exe wouldn't know what to do

    The correct way to issue that shell command would need escaped quatation marks like this:
    Code:
    Shell "C:\Windows\System32\mspaint.exe ""C:\My Picture.jpg"""
    Which sends the following to the command line:
    Code:
    C:\Windows\System32\mspaint.exe "C:\My Picture.jpg"
    Because "C:\My Picture.jpg" is surronded in quotes it doesn't get split at the space character and is treated as one argument instead of two.

    *Note: if the path to the executable you're trying to run has any spaces in it you'll need to surround it in quotation marks as well:
    Code:
    Shell """C:\Windows\System32\mspaint.exe"" ""C:\My Picture.jpg"""

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    @Dave,
    What exactly is the purpose of opening all *.jpgs at once? Just curious.
    My searching (Google) suggests same as kd2017 ---mspaint opens 1 named file.

  7. #7
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    See below for how you might loop through the images in a directory
    Code:
    Public Sub test()
        Dim paint_path As String
        Dim base_dir As String
        Dim file_name As Variant
        Dim cmd As String
        
        'path to mspaint executable
        paint_path = "C:\Windows\System32\mspaint.exe"
        
        'path to the directory with the image files
        base_dir = "C:\Users\kd\Desktop\testing\"
        
        'image files to open
        file_name = Dir(base_dir & "*.jpg")
        While file_name <> ""
            'build the shell command
            cmd = """" & paint_path & """ """ & base_dir & file_name & """"
            
            'preview the command we just built
            Debug.Print cmd
            
            'execute the shell command
            'Shell cmd
        
            'Move to the next file
            file_name = Dir
        Wend
    End Sub
    However, for just resizing images you can probably automate that. If you're able to install 3rd party software on the user's computer you can do something like this: https://stackoverflow.com/questions/...-resize-images

  8. #8
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Just to check...are you using Windows 11? If so there is (or was) a known issue as the Paint program has changed fundamentally

    I don't have Win 11 so cannot check but if its relevant, see if this article helps: Useful Solutions To Fix Paint Not Working In Windows 11 (minitool.com)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Quote Originally Posted by isladogs View Post
    Just to check...are you using Windows 11? If so there is (or was) a known issue as the Paint program has changed fundamentally

    I don't have Win 11 so cannot check but if its relevant, see if this article helps: Useful Solutions To Fix Paint Not Working In Windows 11 (minitool.com)
    Dave is showing Win10 and Access 2016?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    I am trying to open them in ms paint to resize them for emailing
    I tend to recall a thread involving image resizing with vba and an api. I'll have to check when I get home.
    Wia? maybe?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  11. #11
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  12. #12
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,185
    Hi guy's thank you very much, unsure based on all of your comments that you can't do multiple files just a single file that has a file name rather that a wildcard to try and open all

    i can open a single file as i have this option else where on systems but will look at and perhaps adjust suggestions kindly posted

    Thanks Again

  13. #13
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,185
    Just to answer, i wanted to for example take 3 images of maybe

    damaged goods inbound or

    these 3 images are an example of what was sent

    not necessarily 3 images but wouldn't be over 10

    Then my target was to, either rename all files from the Camera Drive into a folder even if the names are 1-29-07-22.jpg / 2-29-07-22.jpg / 3-29-07-22.jpg

    Attach to the body of an email.

    So the aim was to move from Camera Path
    Rename them all
    open with paint to resize (looks sensible on mail body), i do this now with 1 x collection image no problem
    was unsure if i can open all 3! perhaps i open the 1st one, Open paint, Resize, Save then msgbox("Open Images 2), follow same process etc..
    generate an email
    attach to html email

    hope this makes sense

  14. #14
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Quote Originally Posted by Welshgasman View Post
    Dave is showing Win10 and Access 2016?
    Yes I know but that profile info is often out of date
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  15. #15
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

Page 1 of 4 1234 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Opening all pdf files in a folder
    By tuniwes in forum Programming
    Replies: 4
    Last Post: 10-27-2020, 05:16 AM
  2. Opening AutoCAD files
    By azinin in forum Access
    Replies: 1
    Last Post: 10-06-2016, 05:25 PM
  3. opening multiple files
    By stephenaa5 in forum Programming
    Replies: 15
    Last Post: 02-07-2014, 08:57 PM
  4. Replies: 5
    Last Post: 01-29-2013, 07:58 PM
  5. Opening .mdb files under Windows 7
    By GeoffGreen in forum Access
    Replies: 1
    Last Post: 08-08-2012, 04:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums