Export Chart With PopUp Window

geospatial

Active Member
Joined
Sep 2, 2008
Messages
290
I currently have a macro that will export all the charts i have on a worksheet. At this time it is only one worksheet at a time.

The code I have is

Sub create_jpeg()

Application.Screenupdating = False
Dim mychart As Chart
Set my chart = ActiveSheet.ChartObjects(1).Chart
mychart.Export Filename:="T:\CEHC\Intel\mychart.jpg", Filtername:="JPG"
End Sub

Is there a way to bring a popup window to allow the user to select save location and filename?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Using the power of Google:
Code:
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type

'API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long

Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Here let us use the above shell functions to open the browse directory dialog

Sub Show_BrowseDirectory_Dialog()

' BrowseForFolder
' SHBrowseForFolder API Function Example

Dim dirInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer
Dim mychart As Chart

Set my chart = ActiveSheet.ChartObjects(1).Chart

' Set Default Root folder = Desktop
dirInfo.pidlRoot = 0&

dirInfo.lpszTitle = "Browse directory!"

' Type of directory
dirInfo.ulFlags = &H1

' Show the Browse Dialog
x = SHBrowseForFolder(dirInfo)

' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
mychart.Export Filename:=Left(path, pos - 1) & InputBox("Please select a filename","Save As..."), Filtername:="JPG"
Else
MsgBox "Browse a Directory..."
Show_BrowseDirectory_Dialog
End If


End Sub
Code taken from here.
 
Upvote 0
Nevermind. Typo in earlier text. Looking for a possible other typo now. Will give praise when i get working. Thanks
 
Upvote 0
I am now getting a run time error '1004'

Method 'Export' of object'_Chart' failed on the line

mychart.Export Filename:=Left(path, pos - 1) & InputBox("Please select a filename","Save As..."), Filtername:="JPG"

Any ideas?
 
Upvote 0
Try debugging it.

First try Left(path, post - 1) & "filename.jpg"

See if that works. If so, the inputbox is wrong.

If not, then the Left(path, post - 1) may be wrong. Echo it to the debugger to make sure it is a proper path.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,432
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top