msoFileDialogSaveAs - How To Implement In This Macro

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
4,846
Cross Posted : msoFileDialogSaveAs - How To Implement In This Macro

The following macro will successfully save an embedded image to the DESKTOP. The path is hard coded.

I am needing to implement the msoFileDialogSaveAs so the USER can select where the embedded image is to be saved.
Please assist me in editing this code so it uses the msoFileDialogSaveAs object.

Thank you.


VBA Code:
Sub SaveShapeAsPicture()

Dim cht As ChartObject

Dim ActiveShape As Shape

Dim UserSelection As Variant

'Ensure a Shape is selected

  On Error GoTo NoShapeSelected

    Set UserSelection = ActiveWindow.Selection

    Set ActiveShape = ActiveSheet.Shapes(UserSelection.Name)

  On Error GoTo 0

'Create a temporary chart object (same size as shape)

  Set cht = ActiveSheet.ChartObjects.Add( _

    left:=ActiveCell.left, _

    Width:=ActiveShape.Width, _

    top:=ActiveCell.top, _

    Height:=ActiveShape.Height)

'Format temporary chart to have a transparent background

  cht.ShapeRange.Fill.Visible = msoFalse

  cht.ShapeRange.Line.Visible = msoFalse

  

'Copy/Paste Shape inside temporary chart

  ActiveShape.Copy

  cht.Activate

  ActiveChart.Paste

 

'Save chart to User's Desktop as PNG File

  cht.Chart.Export Environ("USERPROFILE") & "\Desktop\" & ActiveShape.Name & ".jpeg"

'Delete temporary Chart

  cht.Delete

'Re-Select Shape (appears like nothing happened!)
  ActiveShape.Select

Exit Sub

'ERROR HANDLERS
NoShapeSelected:
  MsgBox "You do not have a single shape selected!"
  Exit Sub

End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
NOTE: THIS HAS BEEN ANSWERED AT THE OTHER FORUM. I DON'T KNOW HOW TO MARK THIS AS SOLVED.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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