I have added a reference to Microsoft.Office.Interop.Word 12.0.0.0. I have Visual Studio 2008 and Microsoft Word 2010(Starter).
string filePath = #"C:\PP.docx";
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.ApplicationClass();
// create object of missing value
object miss = System.Reflection.Missing.Value;
// create object of selected file path
object path = filePath;
// set file path mode
object readOnly = false;
// open document
Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
// select whole data from active window document
docs.ActiveWindow.Selection.WholeStory();
// handover the data to cllipboard
docs.ActiveWindow.Selection.Copy();
// clipboard create reference of idataobject interface which transfer the data
System.Windows.Forms.IDataObject data = Clipboard.GetDataObject();
I get the error mentioned below:
Retrieving the COM class factory for component with CLSID
{000209FF-0000-0000-C000-000000000046} failed due to the following
error: 80040154. at Microsoft.Office.Interop.Word.Application word => new Microsoft.Office.Interop.Word.ApplicationClass();
Thanks,
Sachin K
The Office Starter 2010 edition is limited and does not support automation.
You need to get an appropriate full Office suite (e.g. the Professional edition).
For more information about the limitations see http://www.microsoft.com/oem/en/products/office/pages/office_2010_starter.aspx
Related
When I try to open an Excel document I have this error
System.Runtime.InteropServices.COMException (0x800706BE): The remote
procedure call failed.
I built an application for my company, it works fine on every computer but on my boss computer it stopped working when he the app has to open an Excel document.
I have tried to change the Permissions in Component Services but it didn't fix it.
I am working on Windows 7.
Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
object missing = Type.Missing;
Excel.Range xlRange;
Excel.Sheets xlSheets = null;
Excel.Worksheet xlSheet = null;
Excel.Workbook xlWorkbook = null;
xlWorkbook = excelApp.Workbooks.Open(filePath, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing);
I need to automate the adding templates (.dot) in existing word document.
I can open the existing document like below
Dim ObjWord As New Microsoft.Office.Interop.Word.Application
Dim wrdoc As Microsoft.Office.Interop.Word.Document
Dim missing = Type.Missing
wrdoc = ObjWord.Documents.Open("D:\T_F\TandF_Sample.doc", missing, True, missing, missing, missing, _
missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
After that i need to attach the template file ("D:\Temp.dot"). is it possible to do this?
anyone plz help me with sample code.
wrdoc.AttachedTemplate = "d:\temp.dot"
I have this code to open a WorkBook on SharePoint, it works perfectly when im on local server but when i access remotely fails to that sharepoint site EX:
(Local = Success) (MachineA to SharePoint = Fail)
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = SPContext.Current.Site)
{
using (SPWeb web = SPContext.Current.Web)
{
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
var wb = app.Workbooks;
wb.Application.Visible = false;
string opl = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
//The issue happens here
var file = wb.Open(fileToOpen.ToString(), Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing);
}
}
}
My environment is:
SharePoint 2010
Windows Server 2008
Interop 14
Any ideas ? i tried adding the Network Service Account to the Excel Application in dcomcnfg but anyway i use RunWithElevatedPrivilage that uses the TEST\administrator account.
Is it possible to call a VBA function (in Access) which takes two string parameters from the outside world (for instance from c# but others will do too)?
This is an example of a call from C# to an access database function that I have used in the past to create a similar feature.
private void btnRunVBAFunction_Click(object sender, System.EventArgs e)
{
Access.Application acApp = new Access.ApplicationClass();//create msaccess
application
acApp.OpenCurrentDatabase(#"C:\temp\db1.mdb",false ,null);//open mdb file
object oMissing = System.Reflection.Missing.Value;
//Run the Test macro in the module
acApp.Run("Test",ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,
ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing
,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing
,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing
,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing
,ref oMissing,ref oMissing);
acApp.Quit();//exit application
}
This is the site that I have used in the past.
http://bytes.com/topic/c-sharp/answers/255310-run-microsoft-access-module-vs-net-c
There's a KB article on automating Access from C# which should get you started.
Using VSTO, I've created a custom tab in the Ribbon designer and added some groups and button controls there. When user clicks one of the buttons, I'd like to connect to a SharePoint site and open a word document from it in Word (an instance is already open). I'm able to connect to the SharePoint site already and have the URLs to the documents I want to open.
But how can I actually load these documents into Word? I'm already in the code-behind in Word, so how can I target the Word instance I'm in and open a file there?
Thanks in advance.
You would have to use the Word API to open a document. See this link for a reference. You may have to update it based on the API version you use.
private void button1_Click(object sender, System.EventArgs e)
{
// Use the open file dialog to choose a word document
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
// set the file name from the open file dialog
object fileName = openFileDialog1.FileName;
object readOnly = false;
object isVisible = true;
// Here is the way to handle parameters you don't care about in .NET
object missing = System.Reflection.Missing.Value;
// Make word visible, so you can see what's happening
WordApp.Visible = true;
// Open the document that was chosen by the dialog
Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
// Activate the document so it shows up in front
aDoc.Activate();
// Add the copyright text and a line break
WordApp.Selection.TypeText("Copyright C# Corner");
WordApp.Selection.TypeParagraph();
}
}