+ Reply to Thread
Results 1 to 3 of 3

VBA code works in debug mode but misses steps running in normal mode

  1. #1
    Registered User
    Join Date
    07-15-2015
    Location
    Aarhus, Denmark
    MS-Off Ver
    MS Excel 2010
    Posts
    2

    VBA code works in debug mode but misses steps running in normal mode

    Hi there,

    I have made a code (adapted from http://www.thespreadsheetguru.com/bl...lides-with-vba) that copies ranges from multiple worksheets to separate powerpoint slides.
    When running the code some ranges are not pasted into the powerpoint (e.g. 28 ranges are pasted correctly but 2 are missing). Running it again there could be 26 ranges pasted correctly but 4 missing. Sometimes even all ranges are pasted correctly! It drives me crazy. When debugging it seems like the code is working at all times, but when running the code is unreliable. Can someone please help? Maybe I need an Do event, but I do not know how to incorporate. Below is the critical part of the code (line marked in bold) that tends to fail when running:

    'List of PPT Slides to Paste to
    MySlideArray = Array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31)

    'List of Excel Ranges to Copy from
    MyRangeArray = Array(Worksheets("TILNYKAPACITET").Range("A1:I36"), Worksheets("Pladelaser - MSK4001").Range("A1:H36"), Worksheets("Rørlaser - MSK4002").Range("A1:H36"), _
    Worksheets("Revolver - MSK3351").Range("A1:H36"), Worksheets("Kantpres - MSK0421").Range("A1:H36"), Worksheets("Bukkecenter - MSK0406").Range("A1:H36"), _
    Worksheets("Pladelinie - MND01-Pladelinie").Range("A1:H36"), Worksheets("CO2 - MND12CO-2").Range("A1:H36"), Worksheets("Mandskab RAL - MND01").Range("A1:H36"), _
    Worksheets("Ideal hyldeautomat - MSK0717").Range("A1:H36"), Worksheets("Mandskab specialprod. - MND05").Range("A1:H36"), Worksheets("Epoxy - MSK1300").Range("A1:H36"), _
    Worksheets("Montage - MND04").Range("A1:H36"), Worksheets("Træproduktion - MND06").Range("A1:H36"), Worksheets("CNC Træ - MSK8500").Range("A1:H36"), _
    Worksheets("Bejdse og voks Træ - MSK8850").Range("A1:H36"), Worksheets("Maling og lak Træ - MSK8800").Range("A1:H36"), Worksheets("Montage Træ - MSK8900").Range("A1:H36"), _
    Worksheets("LV Rørsav - MSK2200").Range("A1:H36"), Worksheets("LV Combi-laser - MSK4010").Range("A1:H36"), Worksheets("LV Kantpres - MSK0421").Range("A1:H36"), _
    Worksheets("LV Rørlokker (lille) - MSK3022").Range("A1:H36"), Worksheets("LV Rørlokker (stor) - MSK3024").Range("A1:H36"), Worksheets("LV CO2-robot - MSK2353").Range("A1:H36"), _
    Worksheets("LV CO2 manuel - MSK2381").Range("A1:H36"), Worksheets("LV Manuel svejs - MSK2402").Range("A1:H36"), Worksheets("LV Pg 12 svejser - MSK0727").Range("A1:H36"), _
    Worksheets("LV LIBRA aut. svejs - MSK0746").Range("A1:H36"), Worksheets("LV Epoxy - MSK1300").Range("A1:H36"), Worksheets("LV Montage - MND04").Range("A1:H36"), _
    Worksheets("TILNYKAPACITET").Range("A1:I36"))

    'Loop through Array data
    For x = LBound(MySlideArray) To UBound(MySlideArray)
    'Copy Excel Range
    MyRangeArray(x).Copy

    'Paste to PowerPoint and position

    On Error Resume Next
    Set shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2) 'Excel 2007-2010
    ' Set shp = PowerPointApp.ActiveWindow.Selection.ShapeRange 'Excel 2013
    On Error GoTo 0

    'Center Object
    With myPresentation.PageSetup

    shp.Left = (.SlideWidth \ 2) - (shp.Width \ 2)
    shp.Top = (.SlideHeight \ 2) - (shp.Height \ 2)

    End With

    Next x

    Thanks in advance!
    Best regards

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,754

    Re: VBA code works in debug mode but misses steps running in normal mode

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    07-15-2015
    Location
    Aarhus, Denmark
    MS-Off Ver
    MS Excel 2010
    Posts
    2

    Re: VBA code works in debug mode but misses steps running in normal mode

    Found a solution myself:
    Please Login or Register  to view this content.
    insert after .pastespecial did the trick
    Last edited by supereeg; 10-19-2016 at 04:51 AM. Reason: Solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Why is Excel VBA executing a command corretly in debug modus but not in normal mode?
    By flextexmex in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-02-2015, 06:49 AM
  2. VBA Code Runs in Debug Mode But Returns Type Mismatch Error Outside Debug Mode
    By valerie.k.chiang in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-24-2014, 03:48 PM
  3. [SOLVED] Code skips on Run Mode but runs fine on F8 (Debug Mode)
    By RaquelAR in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-25-2013, 01:05 PM
  4. VBA code only works correctly in Debug mode
    By tpthatsme in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2012, 12:51 PM
  5. Can I use VBA to check if the sheet(xxx) is in Page-Break mode or Normal mode ?
    By BaLLZaCH in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2008, 09:03 AM
  6. Macro Works but not in Debug Step mode
    By Bob Smedley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2006, 12:35 PM
  7. [SOLVED] Excel 2000 Code works except in debug mode
    By Bob Smedley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-23-2006, 09:25 PM

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