Reputation: 630
try
{
Microsoft.Office.Interop.Word.Application WordObj = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application") as Microsoft.Office.Interop.Word.Application;
Office.CustomXMLParts currClassification = WordObj.ActiveDocument.CustomXMLParts;
}
catch(Exception ex)
{
//I am getting, This command is not available because no document is open. this error here.
}
When I am using above code, I am getting this error:
This command is not available because no document is open.
Regards
Upvotes: 1
Views: 7645
Reputation: 196
Don't know how but adding a folder named "Desktop" in the below locations solved my issue.
C:\Windows\SysWOW64\config\systemprofile
C:\Windows\System32\config\systemprofile\
Upvotes: 0
Reputation: 296
Actually you are trying to access active document when there is no document open in word application so you are getting an error. Your word application is open but no document is opened in it i.e. you are at home screen of word application as shown in image.
Try to use following code to check whether there are any open documents in your application and then access ActiveDocument
if(WordObj.Documents.Count >= 1)
Upvotes: 3