+ Reply to Thread
Results 1 to 2 of 2

Code to save picture to a file

  1. #1
    Registered User
    Join Date
    01-25-2018
    Location
    london
    MS-Off Ver
    365
    Posts
    43

    Code to save picture to a file

    Hi all,

    I've made a start on code for copying a cell and pasting it as a picture, But I'd like to save it as a picture file in a particular location.

    From reading, I know i'd need to past it into a blank chart then export said chart. I'm okay with basic VBA but have really struggled to adapt existing codes for this.

    So far i've got :

    Please Login or Register  to view this content.
    This code, copies the selected cell, pastes it in the same row 17 columns right of it and gives it a name based on what is in a specified cell 8 columns to the left (of where the picture was pasted).
    E.g. A2 copy, paste in R2 and give it a name from J2

    I'd like to be able to save this as a .png file with a path "C:......" with the file name being the picture name.

    Please can someone help

  2. #2
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Code to save picture to a file

    I'm playing around to try with a code like this :

    Please Login or Register  to view this content.
    Give the macro above to a button on a sheet if needed.

    The user process is like this :
    1. Select the cells to be copied as a picture
    2. Click the button which has the macro with the code above OR run the code above via VBA editor
    3. The code will ask the user to give the name of the picture
    4. Type the name of the picture without extension

    The code process is like this :
    1. The selected cells is copied as picture
    2. Create a new workbook
    3. Paste the picture to the new workbook
    4. Ask the user to input/type a name (say the name is pic001)
    5. Save the new workbook as htm file in "D:/test/" folder
    This will create "D:/test/pic001_files/" folder and create "D:/test/pic001.htm" file.
    Inside "D:/test/pic001_files/", the copied cells image is automatically named to "image001.png"
    6. Close the newly created workbook
    7. Rename the "image001.png" to "pic001.png"
    8. Move the "pic001.png" to "D:/test" folder
    9. Delete the "D:/test/pic001_files/" folder
    10. Delete the "D:/test/pic001.htm" file.

    Please note that the code doesn't check if the same image file name already exist in "D:/test" folder.
    So if the next time the user input "pic001" again, it will throw an error on step 8.

    I've found on the internet there is another way by creating a chart which maybe is simpler than mine, but I haven't tried it yet.

    Just now I'm playing around with the code I've found in the internet using chart :
    Please Login or Register  to view this content.
    Last edited by karmapala; 04-17-2020 at 02:20 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 07-07-2018, 06:53 PM
  2. [VBA] Save Range as picture, save to file, attach to email
    By Armitage2k in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-23-2018, 07:34 AM
  3. Save picture located in workbook to .jpg file
    By PENGUIN88 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-13-2016, 05:39 AM
  4. Click on picture and run macro to replace existing picture with selected picture file
    By houseflipsheet in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-14-2014, 12:02 AM
  5. Replies: 4
    Last Post: 06-29-2013, 11:38 AM
  6. Excel 2010 file with VBA save and send code works-but file can't be found.
    By carlton.clay in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-13-2013, 09:46 AM
  7. Need a VB code (file names, hyperlinks, picture comments)
    By jeseravi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-07-2012, 10:19 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1