Document.Variables bad for docx file in Microsoft Live
Hi;
If this is the wrong forum, please point me to the correct one.In my Word AddIn I create a variable (document is an object of the class Document):
object obj = "dave";
document.Variables.Add("WR_DATA", ref obj);I then save the document, close it, and reload it using:
foreach (Variable var in document.Variables)
{
if (var.Name == "WR_DATA")
{
buf = var.Value;
break;
}And get a totally random string like "w:autofitToFirstFixedWidthCe"
If we run on a Word file that is on the local drive this works fine.
And this is code that has worked fine forever for local & networked
office documents forever.??? - thanks - dave
Cubicle Wars - www.windwardreports.com/film.htm- Moved byYi-Lun LuoMSFTThursday, June 18, 2009 5:26 AMOff topic. (From:Live Framework)
All Replies
- Hello, just to clarify, are you using Office Live? I ran the following code against a local docx file, a file stored in Live Mesh, as well as a file stored in Office Live. I can reproduce your problem only with the file in Office Live. The file in Live Mesh works fine for me. This forum is for Live Framework (Live Mesh). If you can confirm this problem only occurs for files in Office Live, I'll try to see if there's a more appropriate forum for you.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.DocumentBeforeSave += new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeSaveEventHandler(Application_DocumentBeforeSave);
this.Application.DocumentOpen += new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentOpenEventHandler(Application_DocumentOpen);
}
void Application_DocumentBeforeSave(Microsoft.Office.Interop.Word.Document Doc, ref bool SaveAsUI, ref bool Cancel)
{
object obj = "dave";
if (this.Application.Documents.Count > 0)
{
var document = this.Application.ActiveDocument;
document.Variables.Add(
"WR_DATA", ref obj);
}
}
void Application_DocumentOpen(Microsoft.Office.Interop.Word.Document Doc)
{
if (this.Application.Documents.Count > 0)
{
var document = this.Application.ActiveDocument;
foreach (Variable var in document.Variables)
{
if (var.Name == "WR_DATA")
{
string buf = var.Value;
break;
}
}
}
}
Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights. - From your other threads, it seems that you're indeed working with Office Live. I'll move this thread to the Office Live forum.
Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights. - This may be a general Word bug as it is now happening on local files and MS says it is a known issue.
thanks - dave
Cubicle Wars - www.windwardreports.com/film.htm


