msoFileDialogSaveAs - How To Implement In This Macro

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
5,004
Office Version
  1. 2019
  2. 2007
Platform
  1. Windows
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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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