Modifying Comments in Shapesheet through VB

  • Thread starter Michael, TransmissionsLLC
  • Start date
M

Michael, TransmissionsLLC

I am trying to modify the text of an existing comment in a visio document
through vba, but am having some problems with it.

The pertinent piece of code is...

vsoPage2.PageSheet.CellsSRC(visSectionAnnotation, iComment,
visAnnotationComment).Formula = xmlNodeList.Item(i).Text

where xmlNodeList.Item(i).Text is the content of a node in an xml document
loaded into the MSXML parser.

Any ideas on why this is tanking?

Thanks in advance.

Michael
 
D

Dawn Wright [MSFT]

Michael,

The string needs to be wrapped in quotes to make it a string formula, and if
you have quotes within the string itself, they need to be delimited with an
additional quote so that they aren't confused with the quote that ends the
string (confusing, huh?).

Try recording a macro where you type text into a comment and look at the
results of the macro to see what I mean.

Here is some sample C# code that can be used to transform a string to the
formula string you need:

/// <summary>This method converts the input string to a Visio string by
/// replacing each double quotation mark (") with a pair of
/// double quotation marks ("") and then adding double quotation
/// marks around the entire string.</summary>
/// <param name="inputValue">Input string that will be converted
/// to Visio string</param>
/// <returns>A converted Visio string that can be programmatically
assigned
/// to a ShapeSheet cell is returned. Note that the string cannot be
directly
/// pasted into a ShapeSheet cell because it doesn't have an "=" at its
/// beginning.</returns>
public string StringToFormulaForString(string inputValue) {

string result = "";
string quote = "\"";
string quoteQuote = "\"\"";

result = inputValue != null ? inputValue : String.Empty;

// Replace all (") with ("").
result = result.Replace(quote, quoteQuote);

// Add ("") around the whole string.
result = quote + result + quote;

return result;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top