XlDialogFormatNumber

Add-in Express™ Support Service
That's what is more important than anything else

XlDialogFormatNumber
Activating a cell in a hidden worksheet stored in an xlam 
Nicholas Hebb




Posts: 92
Joined: 2008-08-22
Per what Eugene wrote, you would need to create separate Dialogs and Dialog objects and release accordingly.


Excel.Dialogs xlDialogs = ExcelApp.Dialogs;
Excel.Dialog xlDialogFormatNumber = xlDialogs[Excel.XlBuiltInDialog.xlDialogFormatNumber];
Posted 26 Jul, 2012 07:30:06 Top
Lennaert Goris




Posts: 19
Joined: 2012-07-05
Thnx, I've changed my code to include this.


private string GetNumberFormat() { 
    // Create all COM variables outside of the try/catch block so we can release in a finally   
    Excel.Dialogs xlDialogs = null;
    Excel.Dialog xlDialogFormatNumber = null; 
    Excel.Range activeCell = null; 
    string chosenNumberFormat = string.Empty; 
    string restoreNumberFormat = string.Empty; 
 
    try { 
        activeCell = AddinModule.CurrentInstance.ExcelApp.ActiveCell; 
        if (activeCell != null && activeCell.NumberFormat != null) { 
            restoreNumberFormat = activeCell.NumberFormat.ToS tring(); 
            xlDialogs = ExcelApp.Dialogs;
            xlDialogFormatNumber = xlDialogs[Excel.XlBuiltInDialog.xlDialogFormatNumber]; 
            xlDialogFormatNumber.Show(); 
 
            if (activeCell.NumberFormat != null) { 
                chosenNumberFormat = activeCell.NumberFormat.ToS tring(); 
            } 
 
            activeCell.NumberFormat = restoreNumberFormat; 
        } 
    } catch { 
        // display message 
    } finally { 
        if (xlDialogFormatNumber != null) { 
            Marshal.ReleaseComObject(xlDialogFormatNumber); 
        } 
        
        if (xlDialogs != null) {
            Marshal.ReleaseComObject(xlDialogs);
        }
        
        if (activeCell != null) { 
            Marshal.ReleaseComObject(activeCell); 
        } 
    } 
 
    return chosenNumberFormat; 
} 
Lennaert Goris
---
Science is what we understand well enough to explain to a computer. Art is everything else we do. - Donald Knuth
Posted 26 Jul, 2012 09:43:48 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Lennaert,

Now your code looks much better ;-)

Good luck with your add-in project!
.NET, Extended MAPI, Windows Phone & RT
Posted 26 Jul, 2012 10:11:43 Top