+ Reply to Thread
Results 1 to 4 of 4

Code does not work after Excel 2013 Upgrade

  1. #1
    Registered User
    Join Date
    05-01-2014
    Location
    Reston, Virginia
    MS-Off Ver
    Excel 2013
    Posts
    4

    Code does not work after Excel 2013 Upgrade

    I am troubleshooting a macro I inherited. This macro is for a database upload. The problem is since we upgraded to Excel 2013, this code does not appear to be running as each time the upload spreadsheet is opened another &ProjectionsUpload menu appears (there are four now). I can right click on them and delete them but as soon as the spreadsheet is opened again they reappear. I did delete Office Cache but that does not help. Any thoughts on changes to this code for Excel 2013? I am a beginner at VB so any help is appreciated.


    Public Sub RemoveBudgetMenu()
    ' Remove custom menu for Projection from the menu bar
    ' This is called from ThisWorkbook when file is closed

    Dim cbWSMenuBar As CommandBar
    Dim i As Integer

    On Error Resume Next
    Set cbWSMenuBar = CommandBars("Worksheet Menu Bar")
    With cbWSMenuBar
    For i = .Controls.Count To 1 Step -1
    If .Controls(i).Tag = sMenuTag And .Controls(i).Caption = "&ProjectionsUpload" Then
    .Controls(i).Delete
    Exit For
    End If
    Next i
    End With

    ' cbWSMenuBar.Controls(sMenuName).Delete
    End Sub

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Code does not work after Excel 2013 Upgrade

    What is sMenuTag? It is not declared or initialized.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    05-01-2014
    Location
    Reston, Virginia
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Code does not work after Excel 2013 Upgrade

    Thank you for your response; I have included the code where the custom menu is built; smenu is declared as a global variable (string) at top of code (did not want to put it all in here).

    Public Sub AddBudgetMenu()
    'Add a custom menu to the menu bar for Projections
    ' This is called from ThisWorkbook when file is opened
    ' modified 11/29/2005 - Brian Patterson
    ' modified 9/28/2007 - Brian Patterson

    Dim cbWSMenuBar As CommandBar
    Dim muProjection As CommandBarControl
    Dim iHelpIndex As Integer

    sMenuTag = SetMenuTag

    Set cbWSMenuBar = CommandBars("Worksheet Menu Bar")
    iHelpIndex = cbWSMenuBar.Controls.Count

    Set muProjection = cbWSMenuBar.Controls.Add(Type:=msoControlPopup, Before:=iHelpIndex)

    With muProjection
    .Caption = "&ProjectionsUpload"
    .Tag = sMenuTag
    With .Controls.Add(Type:=msoControlButton)
    .Caption = "&Show Export Range"
    .OnAction = "ShowExportRange"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .Caption = "&Adjust Export Range"
    .OnAction = "AdjustExportRange"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .Caption = "&Validate Data in Export Range"
    .OnAction = "ValidateData"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .Caption = "&Reset Export Directory"
    .OnAction = "ResetExportDirectory"
    End With
    With .Controls.Add(Type:=msoControlButton)
    .Caption = "&Export Budgets"
    .OnAction = "ExportBudgets"
    End With
    End With
    End Sub
    '-------------------------------------------------------------------------------
    Private Function SetMenuTag() As String
    'Set the menu tag for the current workbook based on the number of instances
    'of the workbook previously opened.
    'Mod by Brian Patterson - 11/29/2005
    'Mod by Brian Patterson - 9/28/2007


    Dim cbWSMenuBar As CommandBar
    Dim i As Integer
    Dim n As Integer
    Dim iExt As Integer

    Set cbWSMenuBar = CommandBars("Worksheet Menu Bar")
    n = 1

    For i = 1 To cbWSMenuBar.Controls.Count
    If cbWSMenuBar.Controls(i).Tag = "ProjectionsUpload" Then
    If Len(cbWSMenuBar.Controls(i).Caption) > 15 Then
    iExt = CInt(Right(cbWSMenuBar.Controls(i).Caption, _
    Len(cbWSMenuBar.Controls(i).Caption) - 15))
    Else
    iExt = 1
    End If

    If iExt >= n Then _
    n = iExt + 1
    End If
    Next i
    If n = 1 Then
    SetMenuTag = "ProjectionsUpload"
    Else
    SetMenuTag = "ProjectionsUpload" & Format(n)
    End If

    End Function

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Code does not work after Excel 2013 Upgrade

    What happens when you step through RemoveBudgetMenu -- do they go away?

    The problem may be related to the fact that Excel 2013 has a single document interface, and I don't have it installed to test.

+ 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. [SOLVED] Code to work in both Excel 2013 and 2003
    By 1eyedjack in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2014, 09:30 AM
  2. Code created in Excel 2010 does not work with Excel 2013
    By Steve@Rugby in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2014, 10:14 AM
  3. Replies: 0
    Last Post: 01-21-2014, 07:48 AM
  4. Macro issue may have when upgrade excel from 2003 to 2013
    By lhollis in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-30-2013, 03:21 AM
  5. code doesnt work after upgrade to 2010
    By jmckee in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-12-2011, 09:57 AM

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