• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro is not running in full mode however, working in break mode!

coolsac12

Member
Hi Team,

I have a macro to export image from my file. When I run it in break mode by pressing F8 its working fine, however when I run by pressing F5 it doesn't work.

Kindly suggest, thanks in advance.

Below is my macro:

Code:
Sub ExportSheet()

Dim lr As Integer
Pth = ThisWorkbook.Path

Worksheets("Main").Range("C35:Q73").CopyPicture xlScreen, xlBitmap

    Application.DisplayAlerts = False
    Set oCht = Charts.Add
  
    With oCht
        .Paste
        .Export Filename:=Pth & "\" & "Img.jpg", Filtername:="JPG"
        .Delete
    End With

End Sub

I observed its taking time where it paste the image, as a macro its fast and skip this step.
 
Last edited by a moderator:
Runs fine on my end. Restart your computer and test.

However, your method will create new chart sheet, and may convert pasted range into chart. If you want to export range as image... use something like below.

Code:
Sub Demo()
Dim expRng As Range
    With ActiveSheet
        Set expRng = .Range("C35:Q73")
        expRng.CopyPicture xlScreen, xlBitmap
        With .ChartObjects.Add(expRng.Left, expRng.Top, expRng.Width, expRng.Height)
            .Name = ActiveSheet.Name & "exp"
            .Activate
        End With
    End With
    ActiveChart.Paste
    ActiveSheet.ChartObjects(ActiveSheet.Name & "exp").Chart.Export ThisWorkbook.Path & "\" & ActiveSheet.Name & ".jpg", "JPG"
    ActiveSheet.ChartObjects(ActiveSheet.Name & "exp").Delete
 
End Sub
 
Thanks for your reply #Chihiro,

However, it's showing error on with statement.
 
Last edited by a moderator:
Upload sample workbook that produces error message. Both code runs without issue on my end.
 
Back
Top