私は C# でワード アドインを作成しています。ドキュメントを作成し、ハイパーリンクを挿入して前面に表示しようとしています。しかし、新しく作成されたドキュメントは前面に出ません。現在のウィンドウの後ろに移動します。以下はコードです:
Word.Document newNoteDoc = new Word.Document();
object oActiveDocFullName = Globals.ThisAddIn.Application.ActiveDocument.FullName;
object oAcitiveDocNameWithoutExt = Path.GetFileNameWithoutExtension(Globals.ThisAddIn.Application.ActiveDocument.Name);
object oActiveDocName = Globals.ThisAddIn.Application.ActiveDocument.Name;
object oScreenTip = (GeneralHelper.pstrNoteFolder + "\\" + txtFileName.Text.Trim() + ".docx").Replace('\\', '/');
object oScreemTipInNewDoc = Globals.ThisAddIn.Application.ActiveDocument.FullName.Replace('\\', '/');
object oMissingReference = System.Reflection.Missing.Value;
object oFileName = "file:///" + GeneralHelper.pstrNoteFolder + "/" + txtFileName.Text.Trim() + ".docx";
object oHyperlinkText = txtHyperlinkText.Text.Trim();
object oFileFormat = Word.WdSaveFormat.wdFormatDocumentDefault;
object oAddToRecentFiles = true;
object oReadOnlyRecommended = false;
object oStartRange = 0;
object oVisible = true;
// OopenFileName = oFileName;
Word.Range rngCurrentRange = Globals.ThisAddIn.Application.Selection.Range;
try
{
//Word.Document maindoc = Globals.ThisAddIn.Application.ActiveDocument;
//insert hyperlink into current document
rngCurrentRange.Hyperlinks.Add(rngCurrentRange, ref oFileName, ref oMissingReference, ref oScreenTip, ref oHyperlinkText, ref oFileName);
Word.Range rngNewRange = newNoteDoc.Range(ref oStartRange, ref oMissingReference);
//insert hyperlink in the new doc.
//Globals.ThisAddIn.Application.ActiveDocument.Activate();
newNoteDoc.Hyperlinks.Add(rngNewRange, ref oActiveDocFullName, ref oMissingReference, ref oScreemTipInNewDoc, oAcitiveDocNameWithoutExt, oActiveDocFullName);
//save the new doc
newNoteDoc.SaveAs2(ref oFileName, ref oFileFormat, ref oMissingReference, ref oMissingReference, ref oAddToRecentFiles, ref oMissingReference,
ref oReadOnlyRecommended, ref oMissingReference, ref oMissingReference, ref oMissingReference, ref oMissingReference,
ref oMissingReference, ref oMissingReference, ref oMissingReference, ref oMissingReference, ref oMissingReference, ref oMissingReference);
//Globals.ThisAddIn.AddTaskPane(newNoteDoc);
//Application.DoEvents();
////newNoteDoc.Application.WindowState=1;
//newNoteDoc.Activate();
//newNoteDoc.Windows.Application.Visible = true;
////newNoteDoc.Activate();
//Thread.Sleep(5000);
//newNoteDoc.Application.Activate();
//newNoteDoc.Application.WindowState = Word.WdWindowState.wdWindowStateMinimize;
//newNoteDoc.Application.WindowState = Word.WdWindowState.wdWindowStateMaximize;
newNoteDoc.Close(ref oMissingReference, ref oMissingReference, ref oMissingReference);
object readOnly = false;
object isVisible = true;
object oMissing = System.Reflection.Missing.Value;
//Make word visible, so you can see what's happening
//Globals.ThisAddIn.Application.Visible = true;
Word.Document NewDoc = Globals.ThisAddIn.Application.Documents.Open(ref oFileName, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible);
NewDoc.Activate();
}
まだ現在のドキュメントはアクティブです。新しく作成したドキュメントをアクティブにして最前面に表示するにはどうすればよいですか。