none
Find cell location of shape RRS feed

  • Question

  • Using c#, what is the most efficient way of getting cell range of shape. On a given worksheet, I have an array of grouped objects (textbox and picture),  I scroll to desired grouped object, using below method.

    private void TrackBar1_Scroll(object sender, EventArgs e)
            {
    
                try
                {
                    Excel.Shape shp = _workSheet.Shapes.Item(TrackBar1.Value + 1);
                    shp.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap);
                    PictureBox1.Image = Clipboard.GetImage();
                }
                catch
                {
                    PictureBox1.Image = null;
                }
    
            }

    In the next step, I want to go to that location in the worksheet, below is an example in which I have a problem getting a cell range where the grouped object exists.  Or maybe there is a better way to approach to this.

    private void ToolStripButtonGoTo_Click(object sender, EventArgs e)
            {
                
                
                try
                {
    
                    Excel.Shape shape = _workSheet.Shapes.Item(TrackBar1.Value + 1);
    
                    Excel.Range range = _workSheet.UsedRange.Find(_workSheet.Shapes.Item(TrackBar1.Value + 1).Name);
    
                    _workSheet.Outline.ShowLevels(ColumnLevels: 2);
    
                    if (range != null)
                    {
                        _excel.Goto(range.Offset[0, -1], true);
                    }
    
    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
    
    
            }
    I hope someone can help here...

    Thanks,


    wesley

    • Moved by Kristin Xie Friday, June 26, 2015 6:45 AM move to more related forum
    Thursday, June 25, 2015 7:14 PM

Answers

  • Hi wesley,

    >>In the next step, I want to go to that location in the worksheet<<

    There are two properties TopLeftCell and BottomRighCell  that relative to the postion that the shape. Then we can go to the location of the cell in the worksheet like code below:

    Dim aShape As Shape
    Set aShape = ActiveSheet.Shapes(1)
    Application.Goto aShape.TopLeftCell
    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 30, 2015 2:10 AM
    Moderator

All replies

  • Hi wesley,

    Based on your code, your case more related to Excel, I'll move this case to Excel for Developers forum for better support.

    Best regards,

    kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, June 26, 2015 6:44 AM
  • Hi wesley,

    >>In the next step, I want to go to that location in the worksheet<<

    There are two properties TopLeftCell and BottomRighCell  that relative to the postion that the shape. Then we can go to the location of the cell in the worksheet like code below:

    Dim aShape As Shape
    Set aShape = ActiveSheet.Shapes(1)
    Application.Goto aShape.TopLeftCell
    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 30, 2015 2:10 AM
    Moderator
  • thanks

    wesley

    Monday, July 6, 2015 2:35 PM