+ Reply to Thread
Results 1 to 15 of 15

Creating an image directory using a macro

  1. #1
    Registered User
    Join Date
    04-21-2014
    Location
    Lovington,NM
    MS-Off Ver
    Excel 2010
    Posts
    56

    Creating an image directory using a macro

    Hello Experts, I have a macro file that creates a image chart using a set of data that changes with each selection from the drop down boxes. I am needing to place another command button to the userform that when selected it makes a JPG image of the current data on the chart and labels the image chart with the 2 values it is comparing each other with? So let's say its "eTemp vs. TGF" when the command button is selected it takes the image that was created and puts it in a directory folder of my choice with it being named to what the 2 values are compared against each other and maybe with a time stamp afterwards?

    Any help with this would be greatly appreciated!
    Attached Files Attached Files
    Last edited by jleal; 08-24-2015 at 07:35 PM.

  2. #2
    Registered User
    Join Date
    04-21-2014
    Location
    Lovington,NM
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Creating an image directory using a macro

    Sorry use this file as i have already added the Command Button where i wanted it to be able to save the image if even possible.
    Attached Files Attached Files

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Creating an image directory using a macro

    rather than delete the chart you use to create the image from for the user form, keep it available for export.

    Please Login or Register  to view this content.
    There is also additional code in load button and userform terminate events.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    04-21-2014
    Location
    Lovington,NM
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Creating an image directory using a macro

    Thank you for your response sir. This works ideally but it seems to only have a one time use. If i select 2 objects to plot and then click save image it lets me name the file for example "testpic.jpg" and converts it to a view able image. This is exactly what i need but if i go to load select another option to plot from the drop down boxes it throws an error in the new code written here highlighted below.

    If Not mMyChart Is Nothing Then
    ' remove existing reference
    mMyChart.Delete
    End If

    Range("T1").Select ' Default Cell Highlight

    Dim MyChart As Chart
    Dim ChartData As Range
    Dim ChartName As String


    I need it to be able to load multiple plots against each other and then be able to save whichever image i choose. I would also like for each image loaded to have a unique name already when i go to save so i can modify if needed. Example: If i plotted "Inclination" vs. "TGF" then when i go to save instead of having to give the image a name that it already provides one for me like so Inclination_TGF_8212015_150103. So its the 2 plots labeled then the date and then the time and this would change with the different items that are loaded on the charts. Something to that nature would be great but the main thing is being able to load multiple charts and saving them without messing up the functionality of things as they are already.

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Creating an image directory using a macro

    that line should be
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    04-21-2014
    Location
    Lovington,NM
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Creating an image directory using a macro

    Yes that fixed the main thing i needed. Now what can i do about having the unique name of the 2 charts when saving the image? Is it in this code that i need to change?

    Private Sub CommandButton1_Click()

    Dim ExportFilename As Variant

    If mMyChart Is Nothing Then
    MsgBox "No current chart to export", vbExclamation
    Else
    ExportFilename = ThisWorkbook.Path & Application.PathSeparator & ComboBox2.Value & "_" & ComboBox1.Value & "_" & Format(Date, "ddmmyyyy") & ".jpg"
    ExportFilename = Application.GetSaveAsFilename(ExportFilename)
    If ExportFilename = False Then Exit Sub

    mMyChart.Export Filename:=ExportFilename
    End If

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Creating an image directory using a macro

    If you want the time added then change the code to create filename

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    04-21-2014
    Location
    Lovington,NM
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Creating an image directory using a macro

    I cant even get it to show the date prior to choosing where i want it saved much less adding the time stamp. The above code just show blank when i go to save and i have to type the name of the file and the extension.

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,345

    Re: Creating an image directory using a macro

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    04-21-2014
    Location
    Lovington,NM
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Creating an image directory using a macro

    Awesome this fixed the naming issue but why wont the extension .jpg carry over?

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,345

    Re: Creating an image directory using a macro

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    04-21-2014
    Location
    Lovington,NM
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Creating an image directory using a macro

    Yup that worked perfectly except the picture was blurry after saving but i changed the extension to .png and its a lot clearer now. Is there a way to make the chart bigger so you can see some distance between the plots?

  13. #13
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,345

    Re: Creating an image directory using a macro

    Try this one.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    04-21-2014
    Location
    Lovington,NM
    MS-Off Ver
    Excel 2010
    Posts
    56

    Re: Creating an image directory using a macro

    Awesome!! That was just a little to big but i can adjust coding size as needed. Thank you Andy Pope & bakerman2 for helping me along the way with this!!!

  15. #15
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,345

    Re: Creating an image directory using a macro

    You're welcome and thanks for the rep

+ 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. [SOLVED] How to Arrange telephone directory ocr image in excel, in table form
    By Inqusitive mind in forum Excel General
    Replies: 12
    Last Post: 01-17-2014, 01:59 PM
  2. [SOLVED] Download Image to specific directory
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-31-2013, 03:00 PM
  3. Replies: 3
    Last Post: 09-08-2012, 07:52 PM
  4. Creating an image directory in Excel 2007
    By Jangaroo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-19-2011, 12:40 PM
  5. Creating a custom image for a button to run a macro
    By ZEvans12 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-15-2011, 03:53 PM
  6. Macro for creating image border upon being clicked?
    By Cheshire in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-09-2009, 04:16 AM
  7. Inserting Hyperlinks to each image in a directory
    By YehWei@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2005, 11:00 AM
  8. Creating an excel macro to open and save sheets to a different directory
    By sem in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-29-2005, 03:05 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