Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8314317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:46:38+00:00 2026-06-08T20:46:38+00:00

In Visio VBA (or COM API) How can i get a shape without expecting

  • 0

In Visio VBA (or COM API)

How can i get a shape without expecting an exception when the shape name is not found?

… in my visio page, there might or might not be a Rectangle Shape with the name “DraftText”.

i want to check that it is there and if yes, do smth.

my code seems like:

Shape waterMarkRect = page.Shapes["DraftText"];
if (waterMarkRect == null)
{
   waterMarkRect = page.DrawRectangle(0, 0, 50, 15);
   waterMarkRect.Name = "DraftText";
   waterMarkRect.NameU = waterMarkRect.Name;
   waterMarkRect.Text = "INCONSISTANT";

   Layer wMarkLayer = page.Layers["WMark"] ?? page.Layers.Add("WMark");
   wMarkLayer.Add(waterMarkRect, 0);
}
...
...

The problem is that, if the shape “DraftText” is not there, i get a COM Exception.

as i am against using try catch block as a coding utility,

i am searching for a way to check for the shape existance prior to taking it such as IDictionary.TryGetValue(, out);

or if(page.Shapes.Contain(“DraftText”))…

Any Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:46:40+00:00Added an answer on June 8, 2026 at 8:46 pm

    Using try catch block

    Shape waterMarkRect = null;
    try { 
        waterMarkRect = page.Shapes["DraftText"];
    }
    catch (Exception){
    }
    
    if (waterMarkRect == null)
    {
       waterMarkRect = page.DrawRectangle(0, 0, 50, 15);
       waterMarkRect.Name = "DraftText";
       waterMarkRect.NameU = waterMarkRect.Name;
       waterMarkRect.Text = "INCONSISTANT";
    
       Layer wMarkLayer = page.Layers["WMark"] ?? page.Layers.Add("WMark");
       wMarkLayer.Add(waterMarkRect, 0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following Visio macro (using VBA) rotates the currently selected shape: ActiveWindow.Selection.Rotate90 How can
I have a shape in Visio which is a group. The group shape can
I'm looking to get an image of a Visio page into the clipboard using
I have a visio shape with shape data column Prop.Name of type string when
How can I catch a double click event on a Visio shape? I would
Using VBA, how do I retrieve custom shape information from a Visio 2003 diagram.
Can graphviz do edge aggregation like visio ? meaning something like o | -------------
Are there any good alternatives for Visio/PowerPoint for drawing architectural diagrams. Both Visio and
I have a database diagram done up in Visio 2003 Professional. Is there any
Is there any way I could draw screenshot design of Silverlight application using Visio?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.