Results 1 to 3 of 3

Code runs through xlsm source workbook but not through the add-in button?

Threaded View

  1. #1
    Forum Contributor
    Join Date
    06-20-2021
    Location
    UK
    MS-Off Ver
    2016
    Posts
    126

    Code runs through xlsm source workbook but not through the add-in button?

    Using same workbook and applying two different methods:

    • Using macro in the xlsm file - works OUTCOME: copies all table ranges and chart objects into separate PPT objects as expected
    • Using macro through add - in button - fails | OUTCOME: creates an empty PPT slide, and finishes the macro

    Sub ExcelChartsToPPt()
    
        Dim PowerPointApp As Object
        Dim myPresentation As Object
        Dim mySlide As Object
        Dim myShape As Object
        Dim oChrt As ChartObject
        
        'Dim for loops
        Dim i As Integer
        Dim j As Integer
    
    
        If PowerPointApp Is Nothing Then _
        Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
        
        On Error GoTo 0
        
        Application.ScreenUpdating = False
        
        Set myPresentation = PowerPointApp.Presentations.Add
        
        'Count number of worksheets and loop that many times
        
    For i = 1 To ThisWorkbook.Worksheets.Count
    
        For j = 1 To Worksheets(i).ChartObjects.Count
        
            Set oChrt = ActiveSheet.ChartObjects(j)
            Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly
            
            
            'copy chart objects from worksheets
            Worksheets(i).ChartObjects(j).Copy
            
            Set rngoChrt = Range(oChrt.TopLeftCell, oChrt.BottomRightCell)
            
            With rngoChrt
            'Range of data cells in relation to the chart
                Set rngData = .Offset(4, .Columns.Count).Cells(1).Resize(10, 3)
                rngData.Copy
            End With
            
            mySlide.Shapes.Paste
            Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
            
            myShape.Left = 200
            myShape.Top = 200
            
            PowerPointApp.Visible = True
            PowerPointApp.Activate
            
            Application.CutCopyMode = False
        
        Next j
    
    Next i
    
    
    End Sub
    Last edited by immigrated4urjob; 08-20-2021 at 07:19 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to open source workbook and save as .xlsm format
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2019, 08:01 AM
  2. Trying to assign macro button that runs on a different sheet in the workbook
    By MrWhiskey in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-21-2017, 03:12 PM
  3. Code runs with F8 but not from button
    By BRISBANEBOB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2014, 02:09 AM
  4. [SOLVED] Copy/Save As xlsm workbook to new xlsm workbook is not copying the code with it
    By Grinchy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-02-2013, 09:30 AM
  5. Ok button runs code 17 times w/o loop.... Why?
    By contaminated in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-28-2012, 05:19 AM
  6. [SOLVED] code behind the command button that runs another macro
    By Vogelmann in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-10-2012, 06:04 AM
  7. Excel - keep a command button from moving after code runs?
    By Dave Little in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2005, 10:05 AM

Tags for this Thread

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