Quantcast
Channel: Visual Studio Tools for Office (VSTO) forum
Viewing all 5157 articles
Browse latest View live

MS Word 2016 addin deployment from visual studio installer

$
0
0
Hello, i have an issue with deploying addin for MS Word.
I created addin in VS 2017, created installer project in Visual studio installer 2017.
I followed instructions from
https://docs.microsoft.com/en-us/visualstudio/vsto/deploying-an-office-solution-by-using-windows-installer?view=vs-2019

Then i wanted to upgrade to VS2019. So i opened project in VS2019, installed Visual studio installer, created new setup proejct and set it up the same as before.

According to guide, i should create 2 entried in registry:
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\Word\Addin\Addin_Name
HKEY_LOCAL_MACHINE\Software\WOW6432Node\Microsoft\Office\Word\Addin\Addin_Name

However for some reason, after the switch to VS2019, i don't see 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\Word\Addin\Addin_Name
being created in registry. I only see WOW6432Node "branch".

I can also see:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Wow6432Node\Microsoft\Office\Word\AddIns\Addin_Name

So how can i force the installer to write my entry into
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\Word\Addin\Addin_Name

Update:
It seems that when i buil x64 install file, it writes both location.
x86 version doesn't write to 
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\Word\Addin\Addin_Name

Thanks.

c# VSTO: How to ExecuteMso with arguments

$
0
0

Hello,

How can I add arguments to ExecuteMso?

Example:

Change font color to Red

Application.CommandBars.ExecuteMso("FontColorPicker(Color.Red))");

Why can not use getdata and setdata after document copy

$
0
0

I want to copy all contents from word to clipboard and process then set back to clipboard

use this code, got exeption when setdata or Clipboard.Clear()

using System;
using System.Windows.Forms;
using Microsoft.Office.Tools.Ribbon;
using HtmlAgilityPack;
using System.Text.RegularExpressions;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;

                    Doc.Application.ActiveDocument.Content.Select();
                    Doc.Application.Selection.Copy();
                    Doc.Application.Selection.Collapse();
                    IDataObject clipData = Clipboard.GetDataObject();
                    String clipHtml = null;
                    if (clipData.GetDataPresent(DataFormats.Html))
                    {
                        clipHtml = (String)clipData.GetData(DataFormats.Html);
                    }

                    String html = "<h1>Hello</h1>";
                    Encoding enc = Encoding.UTF8;
                    string begin = "Version:0.9\r\nStartHTML:{0:000000}\r\nEndHTML:{1:000000}"+ "\r\nStartFragment:{2:000000}\r\nEndFragment:{3:000000}\r\n";
                    string html_begin = "<html>\r\n<head>\r\n"+ "<meta http-equiv=\"Content-Type\""+ " content=\"text/html; charset=" + enc.WebName + "\">\r\n"+ "<title>HTML clipboard</title>\r\n</head>\r\n<body>\r\n"+ "<!--StartFragment-->";
                    string html_end = "<!--EndFragment-->\r\n</body>\r\n</html>\r\n";
                    string begin_sample = String.Format(begin, 0, 0, 0, 0);
                    int count_begin = enc.GetByteCount(begin_sample);
                    int count_html_begin = enc.GetByteCount(html_begin);
                    int count_html = enc.GetByteCount(html);
                    int count_html_end = enc.GetByteCount(html_end);
                    string html_total = String.Format(
                      begin
                      , count_begin
                      , count_begin + count_html_begin + count_html + count_html_end
                      , count_begin + count_html_begin
                      , count_begin + count_html_begin + count_html
                      ) + html_begin + html + html_end;
                    DataObject obj = new DataObject();
                    obj.SetData(DataFormats.Html, new MemoryStream(
                      enc.GetBytes(html_total)));
                    Clipboard.SetDataObject(obj, true, 2, 100);

If I comment out

Clipboard.GetDataObject

Then SetDataObject works well 

But if keep it Clipboard.Clear() or Clipboard.SetDataObject got the same exception :

ErrorCode: -2147221040

Comment out

Doc.Application.Selection.Copy();

Clipboard.SetDataObject also works well.

Why can not use Copy and GetDataObject then SetDataObject at the same time?

I tried .Net 4 and .Net 4.6.1 got the same.

Excel refuses to show VSTO add in

$
0
0

I made a custom ribbon VSTO for excel and had it running perfectly. But because I needed to keep making changes to it I needed it to update automatically. I published it on a network drive and set it to look at updates when it starts. When I first started there was an error that said that the add in could not be loaded because there was another version of it loaded already.

I noticed it was loading from the debug folder and not the publish folder on the network drive. I deleted the previously installed version and cleaned up the debug folder so there was nothing in there. I reinstalled the VSTO from the network drive and started up excel again. I saw that the custom tab was not showing and when I looked at my COM add ins my custom ribbon VSTO was checked and active.

It was not in the disabled list or the inactive list. I tried loading the same VSTO on a separate computer and the same thing happened. So then I recreated the entire VSTO add in from scratch deleted all the previous work and tried to debug the new VSTO and the same problem occurred. There are no error messages telling me what is going wrong.

Programatically opening a view of a contact item in other than the default

$
0
0

One of my clients uses contacts in a public folder. These are kept in synch with their customer, vendor and employee contacts in their bespoke Access front end - SQL back end operations application. Yes, they are not mobile. You will not hold that against them. They employ scores of workers who are not 'knowledge workers.' Maybe a dozen people on staff use a computer.

For a variety of good reasons I want to be able to open a contact item from this folder set to show all fields, as shown here done manually in Outlook for Office 365 for Business Premium (aka Outlook 2016)

How do I do this programmatically? I've been looking through the Outlook object model and don't see any way of accessing the ribbon, setting various properties and then invoking <contactitem>.display

It seems to me I ought to be able to so something like 

-Open a contact item(itsEntryID,theStoreID)

-Set Show.AllFields = True (or something like that)

-contactitem.display

No?

C# powerpoint SmartArt Node TextFrame2.TextRange.Text Setting Text Returns Error

$
0
0

I am trying to replace smartart node text and I get an error when trying to edit any part of the node.

shp.SmartArt.AllNodes[1].TextFrame2.TextRange.Text = "string";

Error Code:

System.Runtime.InteropServices.COMException: 'Error HRESULT E_FAIL has been returned from a call to a COM component.'

It may have to do with permissions to the node or visibility but I also am editing text with TextFrames with no problems. It only has to do with smartart nodes.

shp.TextFrame.TextRange.Text = "string";

I have tried frameworks 4.6 and 4.5 nothing seems to work when editing the node text. I also am directly calling the Microsoft.Office.Interop.PowerPoint.Application and Microsoft.Office.Interop.PowerPoint.Presentation with no usings. I am able to read the text but not set the text. I also am using office 16 .net core as well.

I have office 2019 so that may also be the problem.


Enable/disable pop-up messages about no changes on meeting request in Outlook for Windows.

$
0
0

Hello!

I'm dealing with an application that is an add-in for Outlook and I use Microsoft.Office.Interop.Outlook library.

In some cases I need to avoid pop-up messages "No changes have been made to the meeting request. Do you want to change the meeting request before sending?" when sending update of existing meeting without changes. Is there a way to enable/disable such pop-ups programmaticaly and/or manually somewhere in settings?

Thanks.


ActiveExplorer.ActiveInlineResponse slows down application

$
0
0

Hi,

I have an add-in that is usualy enabled for newly created emails. The task is to enable it for Reply/ReplyAll/Forward inline windows.

For a new email I use the "inspector.CurrentItem as Outlook.MailItem" but for inline explorer windows i have to use "application.ActiveExplorer().ActiveInlineResponse" to get the mailitem object.

Everything is working fine when I use the "Inspector" but when I use the "ActiveInlineResponse" really slows down my application processing. At some point outlook does not respond at all.

In application I pragmatically add attachments, write email header properties, change subject, body etc...

Can anyone explain me why is this happening and how can I fix it? I google it for 1 day now but with no success.

Thanks.


Font size changes when ApplyTemplate is used in Powerpoint

$
0
0

Hi

We are working with a new function in our VSTO application for Powerpoint in which we let the user switch between 4:3 and 16:9 format presentations.

We have succeeded in all parts but one: The font size is mysteriously changed without any understandable reason. The base of this is 2 different templates. One with 4:3 format and one with 16:9. Both templates have SlideMasters set up equally regarding content and font sizes.

If we create a presentation with the normal (4:3) template we have for example a Textbox on page 1 with Arial(Header) font with size 28.

Then we use these commands to switch to a wide presentation:

pres.ApplyTemplate(sizeMallName)
pres.PageSetup.SlideWidth = newSize

In which sizeMallName is full path to the Wide template and newSize is 960.

In the resulting presentation the Textbox on page 1 has changed to Arial(Header) font size 21.

If it was Autosize causing this, then logic says it would switch to a larger font size, not a smaller one.

Why is this happening?

All help is appreciated.



Best Regards Peter Karlström Midrange AB, Sweden


VSTO Excel Add-In: no business case to pay for a code signing cert

$
0
0
I've developed a VSTO Add-In for Excel. It has limited potential use and zero commercial value. So I haven't invested in a code signing certificate.

I "Click once" published the Add-In using a VS Test Certificate to sign it. When I zip up the published files, copy that zip to another machine via an SMB share, and then extract the files on the target machine, I can install it after accepting the scare warning.

When I take the exact same zip and put it on my web site, download it on the exact same other machine, extract the files, and try to install, I can't install it because I get a scare refusal to do so.

I get the general principle of trying to preserve some kind of trace-ability for potentially malicious add-ins. But in this case, the add-in might prove useful to a very limited number of users. I'd like to make it available to those users through some kind of friction-less distribution scheme. (I.e., not snail-mailing floppy disks or something like that.) But I'm not eager to invest hundred$s annually just to make it install-able for them.

Is there a workaround? (e.g., distributing it in a mountable .iso instead of .zip?) Alternatively, is there some way I can self-sign and create a public certificate that users can install that would then allow them to install my add-in they downloaded from the web? If there's a way, can you provide a link to a complete How-To? All my Google results only describe tiny portions of the problem.

Não tenho permissão para usar Excel.dll

$
0
0

Criei um projeto que utiliza API do Excel 2007, recentemente desinstalei o office 2007 e instalei o Office 365 business.

Tive que atualizar a API, mas agora recebo a mensagem que eu não tenho permissão de administrador.

O caminho de acesso é

C:/Windows/assembly/gac_msil/Microsoft.Office.interop.Excel/15.0.0.0__71E9BCE111E9429C

O que está errad ? Pois somente as API do Office está com esse erro? 

0x80029C4A (TYPE_E_CANTLOADLIBRARY)

$
0
0

After installing my application (the installation log looks fine), a particular client (US Military) received the following error when trying to start my application:

 

System.InvalidCastException: Unable to cast COM object of type 'Microsoft.Office.Interop.Word.ApplicationClass' to interface type 'Microsoft.Office.Interop.Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020970-0000-0000-C000-000000000046}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).

 

Based on other responses I have read on this error, it looks like the registry may be corrupted by Anti-virus script blocking software or by multiple instances of Office installed.  Indeed the client is running the Symantec software. Are there other causes I should be aware of?

 

Is there something my code can do to get around this?  I don’t want to have them reinstall Office, as to them it is working fine (i.e. they can start Word and Outlook manually just fine).

 

moving mailbox from exchange to office 365 in .net

$
0
0

Hi Guys,

I am having a .net email sending program. there will be an email account mailbox for email sending. Currently my code accessesthese mailbox by hitting exchange services(using .asmx file). Now we are plan to move this account to office 365.

What are things I have to consider in coding level? what are the configurations I have to make? Can anyone please help me?

Thanks

Outlook VSTO: Saving .msg files with special characters

$
0
0
Hi, I'm having troubles replicating an end-user issue with our VSTO Outlook tool. On their end, our tool throws an exception when saving .msg attachments with special characters (i.e. <, >, |) in its subject. I'm guessing this is because normally, you cannot save files with those characters in its filename to your local directory. However, when trying to replicate it on my machine (as well as some other colleagues), I noticed that the tool strips the special characters from the filename during runtime before attempting to save the file thus no exceptions are thrown. I'm thinking that this maybe because we have different OS configurations with our end users. Is that really the cause? I tried to search for some similar threads but I cannot seem to find the right answer for my case. Would really appreciate if someone could clear things up for me or if you could point me to the correct search keywords as I'm lost in words while trying to figure things out. Thank you!

Prevent actions to be added to the word undo redo OR Remove actions from the undo redo CommandBarComboBox

$
0
0

We are inserting content controls programmatically and we dont want to add actions to the undo stack of word. The only way that we found is to acess the undo command bar combox and to remove the items related to inserting content control action, we are using the code below :

var commandBars = _wordDocument.CommandBars.Cast<CommandBar>();
            var standardCommandBar = commandBars.First(bar => bar.Name.Equals("Standard"));
            CommandBarComboBox undoControl = standardCommandBar.Controls.Cast<CommandBarControl>().First(control => control.Id == 128) as CommandBarComboBox;

undoControl.RemoveItem(1);

The last line (undoControl.RemoveItem(1)) throws a ComException (HRESULT E_FAIL).

Is there any way to remove actions from the undo redo combo box?

Regards.


Write data from C# into PPT using inbuilt packages

$
0
0

What are the inbuilt packages that support writing data into ppt slides in C# 2.0 Framework?

How do I write data into ppt slides in tabular format? Is there a way contents of a C# datatable can be displayed in PPT? or else can the excel sheet be embedded into ppt? 

Thanks for the help in advance.

Where is the documentation for ThisAddIn class of VSTO project?

$
0
0

Using VS2019, I have created a VSTO AddIn WORD project. As we know the default template of this project creates a ThisAddIn class with two events ThisAddIn_Startup and ThisAddIn_Shutdown but no constructor. But when I try to create a constructor of this class as follows, I get the following error:

publicThisAddIn(){}

Error:

there is no argument given that corresponds to the required formal parameter 'factory' of 'AddInBase.AddinBase(Factory, IserviceProvider, string, string)'

Question: What is the cause of this error and how can I create a constructor in ThisAddIn class?

Some Background: I am trying to mimic functionalities of a Winform (Windows Forms) project into a VSTO office project. The Winform project has some code inside its constructor Form(){...} that I need to implement inside the constructor of ThisAddIn class of VSTO projects.


How can I access a created Ribbon from other parts of my application?

$
0
0

I have created a Ribbon in MS Word with several controls and I want to change the value in a Textbox when I change the active document. To catch the event for document change is no problem with a procedure "Application_DocumentChange()". In this procedure I want to access my Textbox in my Ribbon.

Where can I find a reference to my Ribbon?

The Microsoft.Excel Object Library is not listed in Reference Manager in Visual Studio 2019.

$
0
0

Hello, 

I am using Microsoft Office365 for business. I have developed a small code with Visual Studio 2019 VB and needed to link an excel spreadsheet to my code. However, Microsoft Excel Object Library is not available in Reference Manager list. Can you advise me how can I add that reference?

Best Regards

Sertac

Error in Win Forms C# when exporting to Excel

$
0
0

I have a really weird problem and searching the net doesnt help. I have Windows Form app built in Visual Studio C# and some of the app users get an error when trying to export generated report to Excel (my app generates reports). This error comes and goes and I dont get it when I run app myself.

Error is below. Could anyone suggest what can be the cause? As I never got this error myself debugging doesnt really help so I believe problem is not within the code.Error text:

System.Runtime.InteropServices.COMException (0x800A03EC): The specified file wasn't found.

at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)

at Microsoft.Office.Interop.Excel.Shapes.AddPicture(String Filename, MsoTriState LinkToFile, MsoTriState SaveWithDocument, Single Left, Single Top, Single Width, Single Height)

at WindowsFormsApp1.GroupAccOvwAll.btnExport1_Click(Object sender, EventArgs e)

at System.Windows.Forms.Control.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnClick(EventArgs e)

at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ButtonBase.WndProc(Message& m)

at System.Windows.Forms.Button.WndProc(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

private void btnExport1_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            this.Text = "Exporting...";
            Range headersRow;
            Range allData;
            Range updateTimestamp;

            saveFileDialog1.Filter = "Excel Documents (*.xls)|*.xls";
            saveFileDialog1.FileName = "Guarantee Overview - " + dataGridView1.Rows[0].Cells[0].Value.ToString();
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // Copy DataGridView results to clipboard
                dataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
                dataGridView1.MultiSelect = true;
                dataGridView1.SelectAll();
                copyAlltoClipboard();

                object Missing = System.Reflection.Missing.Value;
                Excel.Application excel = new Excel.Application();

                excel.DisplayAlerts = false; // Without this you will get two confirm overwrite prompts
                Excel.Workbook workbook = excel.Workbooks.Add(Missing);
                Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item(1);


                worksheet = workbook.ActiveSheet;
                worksheet.Name = "Summary";
                worksheet.Cells.WrapText = false;
                worksheet.Cells.Font.Name = "Text";
                worksheet.Cells.Interior.Color = Color.FromArgb(255, 255, 255);
                worksheet.Columns[2].NumberFormat = "@";
                worksheet.Columns[4].NumberFormat = "@";
                worksheet.Columns[5].NumberFormat = "@";
                worksheet.Columns[6].NumberFormat = "@";


                // Paste clipboard results to worksheet range
                Excel.Range CR = (Excel.Range)worksheet.Cells[4, 1];
                CR.Select();
                worksheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);
                worksheet.Columns.AutoFit();
                worksheet.Shapes.AddPicture(@"..x.png", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 0, 0, 180, 39);
                allData = worksheet.UsedRange;
                allData.Borders.LineStyle = XlLineStyle.xlContinuous;

                Microsoft.Office.Interop.Excel.Range ur = worksheet.UsedRange;
                Microsoft.Office.Interop.Excel.Range r = worksheet.Cells[4, ur.Columns.Count];
                headersRow = worksheet.Range["A4", r];

                headersRow.Cells.Font.Bold = true;
                headersRow.Cells.Font.Color = Color.FromArgb(255, 255, 255);
                headersRow.Cells.Interior.Color = Color.FromArgb(0, 055, 085);


                worksheet.Cells[2, 5] = worksheet.Cells[5, 20];
                worksheet.Cells[2, 5].Font.Bold = true;
                worksheet.Cells[2, 4] = "Report date:";
                worksheet.Cells[2, 4].Font.Bold = true;
                worksheet.Cells[2, 4].HorizontalAlignment = XlHAlign.xlHAlignRight;

                updateTimestamp = worksheet.Range["T5", "T5"].EntireColumn;
                updateTimestamp.Delete();




                // Delete blank column A and select cell A1
                Excel.Range delRng = worksheet.get_Range("A:A").Cells;
                delRng.Delete(Type.Missing);
                worksheet.get_Range("A1").Select();



                             // Save the excel file under the captured location from the SaveFileDialog
                workbook.SaveAs(saveFileDialog1.FileName, Excel.XlFileFormat.xlWorkbookNormal, Missing, Missing, Missing, Missing, Excel.XlSaveAsAccessMode.xlExclusive, Missing, Missing, Missing, Missing, Missing);
                excel.DisplayAlerts = true;
                workbook.Close(true, Missing, Missing);
                excel.Quit();

                releaseObject(worksheet);
                releaseObject(workbook);
                releaseObject(excel);

                // Clear Clipboard and DataGridView selection
                Clipboard.Clear();
                dataGridView1.ClearSelection();

                // Open the newly saved excel file
                if (File.Exists(saveFileDialog1.FileName))
                    System.Diagnostics.Process.Start(saveFileDialog1.FileName);
            }
        }

        private void copyAlltoClipboard()
        {
            dataGridView1.SelectAll();
            DataObject dataObj = dataGridView1.GetClipboardContent();
            if (dataObj != null)
                Clipboard.SetDataObject(dataObj);

        }

        private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                MessageBox.Show("Exception Occurred while releasing object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }

        }

        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            backgroundWorker1.CancelAsync();
            this.Close();

        }




Viewing all 5157 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>