Results 1 to 8 of 8

Changing file destination and filename based on specified in cell in VBA code

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-22-2016
    Location
    Philippines
    MS-Off Ver
    MS Office 2013
    Posts
    124

    Question Changing file destination and filename based on specified in cell in VBA code

    Hi everyone,

    As new to VBA, how can I modify this so instead of objChart.Export ("C:\Users\dean.martin\Desktop\My Exported Charts\Yesterday's Weather.jpg"), it would use the folder location specified in cell "N10" of "sheet 1" for example? (ie., where N10 = C:\Users\dean.martin\test\ or any other destination folder) and in cell "N9" of "sheet 1" for the file name (ie., where N9 = Today's weather.jpg or any other file name or format)

    Below is my code;

    ---------------------------------------------------------------------------
    Private Sub CommandButton1_Click()
    Dim i As Integer
    Dim intCount As Integer
    Dim objPic As Shape
    Dim objChart As Chart
    'copy the range as an image
    Call Sheet1.Range("A1:J57").CopyPicture(xlScreen, xlPicture)

    'remove all previous shapes in sheet2
    intCount = Sheet2.Shapes.Count
    For i = 1 To intCount
    Sheet2.Shapes.Item(1).Delete
    Next i
    'create an empty chart in sheet2
    Sheet2.Shapes.AddChart
    'activate sheet2
    Sheet2.Activate
    'select the shape in sheet2
    Sheet2.Shapes.Item(1).Select
    Set objChart = ActiveChart
    'paste the range into the chart

    Sheet2.Shapes.Item(1).Line.Visible = msoFalse
    Sheet2.Shapes.Item(1).Width = Range("A1:J57").Width
    Sheet2.Shapes.Item(1).Height = Range("A1:J57").Height
    objChart.Paste
    'save the chart as a JPEG
    objChart.Export ("C:\Users\dean.martin\Desktop\My Exported Charts\Yesterday's Weather.jpg")
    End Sub
    -----------------------------------------------------------------------
    Any help would be greatly appreciated.

    Thanks,
    Dean
    Last edited by dedark05; 05-13-2016 at 04:00 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need to play a wav file based on path and filename in a selected cell using macro: SOLVED!
    By needtoregistersux in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-31-2016, 07:47 PM
  2. Replies: 9
    Last Post: 06-18-2015, 03:12 PM
  3. [SOLVED] How can I stop a linked cell's destination from changing.
    By PistachioPedro in forum Excel General
    Replies: 4
    Last Post: 10-30-2013, 02:01 AM
  4. Download a file with changing filename
    By stokarfi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2013, 01:18 PM
  5. Replies: 0
    Last Post: 09-26-2012, 01:15 PM
  6. Link file with changing filename
    By markpugh in forum Excel General
    Replies: 1
    Last Post: 06-09-2010, 02:46 PM
  7. Replies: 2
    Last Post: 06-25-2009, 02:26 AM

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