Results 1 to 2 of 2

Macro not working properly when called from Button (Running otherwise)

Threaded View

  1. #1
    Registered User
    Join Date
    03-04-2016
    Location
    India
    MS-Off Ver
    2013
    Posts
    3

    Macro not working properly when called from Button (Running otherwise)

    I have a macro which was running from a long time. Suddenly it stopped working. Upon digging I found out that the macro is not running properly only when it is called from the button. If I try the macro through F8 or Developer Tab everything seems to work fine.

    The exact issue is that when called from button the code which is supposed to copy an entire sheet from one workbook to another sheet of a different workbook is pasting the content from below cell instead of A1. As a result excel is not able to paste.

    This is only happening when called from button.Has anyone faced this issue.

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    'Set system properties
        Application.Calculation = xlCalculationManual
        Application.CalculateBeforeSave = True
        Range("CardiacLong_Contents").ClearContents
        Application.ScreenUpdating = False
        
        'Unprotect Process Sheet to insert important data
        Sheets("Process").Select
        ActiveSheet.Unprotect
        
        Dim wb As Workbook
        Dim wbOCLong As Workbook
        Dim ws, wsp As Worksheet
        Set wb = ActiveWorkbook
        Set ws = wb.Worksheets("Cardiac Long")
        Set wsp = wb.Worksheets("Process")
        MsgBox "Open Cardiac OC Long Term Report"
        Set wb = Workbooks.Open(Application.GetOpenFilename)
        'Warning if there are more than one sheets
        If (wb.Sheets.Count > 1) Then
                MsgBox "This HINAI report has two sheets. Please merge them manually and then upload them"
            End
        End If
        If (Columns.Count <= 256) Then
            MsgBox "Please save the input or uploading files as *.xlsx or *.xlsb and then upload them"
            End
        End If
        
        'Add the uploading file name as comment
        wsp.Range("C6").ClearComments
        wsp.Range("C6").AddComment wb.FullName
        
        'Clearing the timestamp to point out the possible error
        wsp.Range("TimeStamp_CardiacLong").ClearContents
        
        wb.Worksheets(1).Range("A1:XFD1048576").Copy
        ws.Range("A1").PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, False
    The error is happening at the last two lines.
    Last edited by 6StringJazzer; 03-05-2016 at 10:34 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Close button not working properly
    By Damian37 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-09-2014, 01:07 PM
  2. [SOLVED] Code working when using F8, but doesnt work properly through button click.
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-01-2013, 09:58 AM
  3. Macro not running properly in Excel 2010
    By tony666 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-08-2011, 09:58 AM
  4. Private sub not working correctly when called from another macro
    By Zyphon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-05-2008, 08:16 PM
  5. Macro not Running Properly in Excel 2003
    By Progress2007 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2008, 08:36 AM
  6. Command button not working properly on different sheet
    By Strikez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2007, 12:36 AM
  7. Replies: 3
    Last Post: 07-06-2006, 02:45 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