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

the saveas method or property is not available becasue a document window is not active

$
0
0

Hello geeks,

I have an outlook 2007 addin developed in c# (VS2008). I have a command that saves the email body as word file. Here is the code:

var doc=mailitem.GetInspector.WordEditor;
doc.SaveAs(ref filename);

This code has been working fine for years. But, suddenly one of the users started receiving an error stating "The saveas method or property is not available becasue a document window is not active.".

In this case, the MailItem is not open in the window. I just grabbed the mailitem from the list of emails from inbox folder.

Can anyone please help me finding the cause of this error?

Thanks in advance.


Create setup of outlook 2016 addin in VS 2016 using installshield

$
0
0

How to create a setup project of outlook 2016 addin in VS 2016 using installshield?

I have tried, and installed, but it doesn't show the add-in functionality in outlook.

Good tutorial on VSTO

$
0
0
I need recommendation on good book/website to learn VSTO, esp for Excel.  Any pointer will be greatly appreciated.

How to programmatically add HTML Code to the body of an Appointment Item? (C#)

$
0
0

Hi,

I am trying to send appointmentItem with body as HTML, but i am not able to do that. As there is no HTMLBODY inside appointmentItem. When i am converting the whole html into RTF and trying to send as RTFBODY in that case proper format of text is not visible and images also not appear.

 As i have viewed many links but on that no proper information is provided.

I am using outlook 2013.

So, can anyone having any idea, how to achieve that.

Thanks in advance

Getting started with document level customisations

$
0
0

I am new to Visual Studio which I am looking to use to develop Office Automation solutions having used VBA directly to this point.

I have installed Visual Studio and am walking through "Walkthrough displaying text in a text box in a document using a button". I have created the project, dragged a TextBox common control from the toolbox onto the document (step 3) and reached step 4 under "Adding controls to the Word document" where I am instructed to "Find TextBox1 in the Properties window drop down box". However when I click on the Properties window drop down I am only offered ActionsPane or ThisDocument and the TextBox control is nowhere to be seen. Its seems such a simple step that I must be doing something bizarrely foolish, but I cannot see it!

Any help would be gratefully received.

Some additional information:  Adding a Word Control works fine ... ie  the control immediately appears in the Properties window. When I drag any Common Control onto the document only a small grey box appears in the document which coupled with the fact that the control does not appear in the properties window implies that I am not set up to add a common control to the document for some reason. Is there a set up setting that I am missing?

select the string or word the user is typing.

$
0
0
i want to catch the word or string the user is typing .how can i do that?thank you

How to reference particular worksheet in VSTO

$
0
0

Greetings community,

Up until now, whenever I had the need for more comfort with manipulating data in Excel, instead of VBA, I was using VS and VB.NET with Microsoft.office.interop referenced. I want to point out that I don’t have any experience with VSTO, and that I need few answers on very basic questions.

Out of curiosity, in new project dialog of VS, I selected Excel workbook.

First question Did I get it right the following: after I finish project of this type, something will be installed in Windows, and every Excel file with the same name as the file in the project, would be provided with some additional functionality, nevertheless where that excel file is saved. And if I take that Excel file from my computer to the other one that does not have my project installed, I would get simple plain Excel file, without any additional functionality.Is this correct?

Well, I named the project ExcelWorkbookProbe, chose .xlsm file type (because I thought I had to) and project was created. I was instantly excited with comfort of possibility of creating ribbon in designer, and things like that, but was disappointed that some things that were working perfectly with interop, here didn’t want to work.

For the beginning I wanted something simple. I named sheet1 “Startings”, and in the first column intended to write time/date stamp whenever the user opens this document. Nothing fancy really, so I opened ThisWorkbook.vb and added this piece of code.

    Private Sub ThisWorkbook_Startup() Handles Me.Startup
        Dim wsS As Worksheet
        wsS = Me.Worksheets("Startings")
        Dim lRow = wsS.Range("a1").CurrentRegion.Rows.Count + 1
        wsS.Range("a" & CStr(lRow)).Value = Now
    End Sub

I thought it would work, but in the second line of sub, where I wanted to reference worksheet object variable, it said it cannot cast COM object to it. First few lines of exception description are:

System.InvalidCastException was unhandled by user code

  HResult=-2147467262

  Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Tools.Excel.Worksheet'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{297DC8D9-EABD-45A1-BDEF-68AB67E5C3C3}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

  Source=ExcelWorkbookProbe

Second question So what do I do? How am I to reference specifically named sheet so I could do something in it. I often have a need to reference several worksheets, and copy some values from one to the other, considering values from the third sheet.

Please help me accomplishing this basic thing that could be easily done in VBA, so I could dig up further.

Programmatically find install directory of a VSTO addIn

$
0
0

In an Office Word VSTO Add-in project I'm saving a Word doc as a Notepad file testFile.txt as in code below. Then the add-in uses that testFile.txt inside the same VSTO project. All that works fine if I'm running the project inside Visual Studio in a debug mode. But when I compile the project, it, of course, creates that AddIn inside word. When I click on a button inside a ribbon of this AddIn, it is supposed to save the Word doc as testFile.txt in a path shown in the first line of the code below. But since AddIn is not in debug mode anymore, it uses the path as C:\User\testFile.txt and hence gives an error shown below. 

Question: How can I make a change to the code below so when AddIn is not in debug mode in Visual Studio, click (callback) of the button on ribbon can still access the folder where AddIn is installed - and thus Word doc is saved as testFile.txt in that installation folder.

string sTestFileName = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())) + "\\testFile.txt";oActiveDoc.SaveAs2(FileName:
sTestFileName , FileFormat: Word.WdSaveFormat.wdFormatText);

Error:
    Word cannot save or create this file. Make sure that the disk you want to save the file on is not full, write-protected or damaged. File: c:\User\testFile.text

NOTE: Question is NOT about when you install your AddIn to a different machine using ClickOnce etc. It's rather when you build your VSTO project in VS by clicking onRebuild Solution submenu, VS automatically installs the AddIn to your corresponding Office App (MS word in my case). How to access that installation folder programmatically in your VSTO project code?




programmatically accessing files included in a VSTO AddIn project from a Ribbon button's callback.

$
0
0

Suppose I have a testFile.txt file in my MS Word VSTO AddIn project's root folder. In Visual Studios's debug mode, I can access this file's path programmatically as follows. [Note: The following code is inside a callback of a Button of Custom Ribbon created in this VSTO project]:

string strFilePath = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory())) + "\\testFile.txt";

As we know, when you build the project by clicking on the Rebuild Project submenu of the Build Meun dropdown in VS, the AddIn (with a custom Ribbon) gets created in Word. But, when I click on the corresponding button in that custom Ribbon, the above code fails since it can't find the path of the testFile.txt. Question: How the above code can be modified so when the project is built (and hence the Addin is created in Word application) the click callback of the corresponding button in the custom ribbon in Word application finds the testFile.txt?

Find first empty cell of a column and paste specific range Only if not a duplicate.

$
0
0

I have an excel database and am using a VBA to find the next empty cell of a column then paste a range to that. I need to be able to do the same I am doing but Without pasting if it is a Duplicate and a message box that states "Duplicate".

I have a button in column "A" of rows 3 thru 260 with similar code for each button so that pressing the button on row "7" uses this code:

Sub End_of_List007()
    Range("B7:D7").Select
    Selection.Copy
    x = Cells(Rows.Count, "J").End(xlUp).Row
    nar = Range("J1:J260" & x).Find("").Row
    Cells(nar, "J").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("G7").Delete
    Range("B7").Select
End Sub

*(I use "Delete" on empty column/cell "G7" to stop the "copy" selection, there is probably a better way that this beginner is just not aware of)

I just need to be able to stop the Duplicate paste to column "J" if it is a Duplicate name or maybe to delete that pasted info if it is first pasted Then checked for duplicate. (With an alert message would be Great but not necessary.)

Thanks,

Master Foo





Add Hyperlinks to Excel Through C#

$
0
0

I have been running this syntax in VBA which works exactly as it should

Function AH()
Dim lr As Long, i As Long
Dim sSheet As String
Dim WS As Worksheet
Set WS = ActiveSheet
lr = Cells(Rows.Count, 2).End(xlUp).Row
For i = 2 To lr
  If WS.Cells(i, 2).Value Like "*,*" Or WS.Cells(i, 2).Value Like "*'*" Or WS.Cells(i, 2).Value Like "*&*" Or WS.Cells(i, 2).Value Like "*-*" Or WS.Cells(i, 2).Value Like "*.*" Then
    ActiveSheet.Hyperlinks.Add Anchor:=WS.Cells(i, 15), Address:="", SubAddress:="'" & WS.Cells(i, 2).Value & "'!A1", TextToDisplay:=CStr(WS.Cells(i, 15))
  Else
    ActiveSheet.Hyperlinks.Add Anchor:=WS.Cells(i, 15), Address:="", SubAddress:=WS.Cells(i, 2).Value & "!A1", TextToDisplay:=CStr(WS.Cells(i, 15))
  End If
Next i
WS.Activate
End Function

Now I just tried to port this to C# and it does not throw any errors, and it seems to function exactly as it shoudl, however whenever I try to click one of the links I get this error 'reference is not valid'

What is incorrect in this syntax?

public void AddHyperlinksToTotalWorksheet()
{
	long lr, i;
	string cellVal;
	Excel.Worksheet WS = xlApp.ActiveWorkbook.ActiveSheet;
	lr = WS.Cells[WS.Rows.Count, 2].End(Excel.XlDirection.xlUp).Row;
	for (i = 2; i <= lr; i++)
	{
		cellVal = WS.Cells[i, 2].Value;
		Excel.Range rangeToHoldHyperlink = WS.Range["O" + i];
		if (cellVal == "*,*" || cellVal == "*'*" || cellVal == "*&*" || cellVal == "*-*" || cellVal == "*.*")
			xlApp.ActiveSheet.Hyperlinks.Add(rangeToHoldHyperlink, "", "'" + cellVal + "!A1", "");
		else
			xlApp.ActiveSheet.Hyperlinks.Add(rangeToHoldHyperlink, "", cellVal + "!A1", "");
	}
}

Location of dlls and other files when a VSTO AddIn project is built in Visual Studio

$
0
0

As explained in this MSDN tutorial, when you run/build an MS Word VSTO project in Visual Studio, it creates your custom office Word AddIn in Word application. You can later remove that AddIn using VS, as explained in the last section of the above mentioned MSDN tutorial, as follows:

Cleaning up the Project

When you finish developing a project, remove the VSTO Add-in assembly, registry entries, and security settings from your development computer. Otherwise, the VSTO Add-in will continue to run every time that you open Word on your development computer.

To clean up the completed project on your development computer

  1. In Visual Studio, on the Build menu, click Clean Solution.

My Question: When custom AddIn is created (as explained in the above MSDN tutorial) where are the corresponding dlls, and other related files (data files etc) from AddIn project get deployed?


outlook get original time of recurring exception item that is opened with drag & drop

$
0
0

I am developing an Outlook VSTO addin on Outlook 2010.

In recurring appointments, I can drag a occurence and drop it to another datetime on my calendar and so open it as an exception item. I use NewInspector event to handle the event, but at this timing, "AppointmentItem.Start" porperty is already updated, i.e. new time. But I want to get the original start time before it is drag and dropped.

As I see the calendar, the occurence is still staying at the original datetime as long as I don't press the send button. It gets updated once I click the "Send" button. Or if I close the window without saving, it goes back to the original datetime. So there must be a way to get the original datetime!

Private Sub ThisAddIn_Startup() Handles Me.Startup
    Me.newInspector = Me.Application.Inspectors
End Sub

Private Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles newInspector.NewInspector
    Dim appt As AppointmentItem = TryCast(Inspector.CurrentItem, AppointmentItem)
Dim startTime = appt.Start
End Sub

Does anybody have an idea?     

Contextual tab for the Outlook inline response in Explorer windows.

$
0
0

Currently it is not possible to use VSTO Visual Designer for Contextual tab for the Outlook inline response in Explorer windows. This makes the use of Visual Designer for Outlook almost not possible. When can we expect this will be supported?

Thanks so much!



Find Last non blank cell in a column and select that cell and cells in next 4 columns of that row.

$
0
0

I want to use a button to look for the last Non-blank cell of a Range and to select that cell and the cells in the 4 columns next to it to delete those values.

Example: If the Last non-blank cell of "H1:H260" is on row 25 then I need to select cells "H25:L25" and delete those values.

I use this formula for finding the first "Blank" cell of a Range but I can't figure out how to get the button to select the next cell up that does have info. and the cells in the 4 columns beside that cell to delete that info.: 

Sub Find_First_Blank_Cell()
    x = Cells(Rows.Count, "H").End(xlUp).Row
    nar = Range("H1:H260" & x).Find("").Row
    Cells(nar, "H").Select
End Sub

Please help a beginner,

Thanks


Can't create project on fresh installation

$
0
0

Hi,

I have installed fresh install of Windows 10 Home (64 bit, en-us), then Office 365 (64 bit, en-us), then updated to last version 1611 (Build 7571.2075) and then VSTO downloaded from https://aka.ms/OfficeDevToolsForVS2015. If I tried to create C# project, Excel Workbook, I get dialog box requesting to allow macro in excel I accept that. After that in some delay I get error Can't create project.

In excel options > Addins I see that addin is in enabled group.

And when error was shown in Event Viewer appers an Application Error

Faulting application name: EXCEL.EXE, version: 16.0.7571.2075, time stamp: 0x5843ee60
Faulting module name: VSTOExcelAdaptor.dll, version: 14.0.23928.0, time stamp: 0x56f88e40
Exception code: 0xc0000005
Fault offset: 0x0000000000026df7
Faulting process id: 0xff4
Faulting application start time: 0x01d25affce988e79
Faulting application path: C:\Program Files\Microsoft Office\Root\Office16\EXCEL.EXE
Faulting module path: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Visual Studio Tools for Office\x64\VSTOExcelAdaptor.dll
Report Id: f3ae6419-14c8-4dbd-bf48-e9615cbd4937
Faulting package full name:
Faulting package-relative application ID: 
How to make it working? I have read many threads about that but nothing helped. In some somebody write that is corrupted version of Office. But how to check what is last working version to downgrade?

Excel Unit Testing with VSTO

$
0
0

We are trying to do unit test with VSTO application (Excel) using C# for code coverage and unable to instantiate the application from unit test project. Need help on this.

Creating a custom button in Outlook Ribbon to display customized New Mail template

$
0
0

Hi Team,

I have a new requirement to create a custom button in Outlook ribbon. Clicking on it, customized new mail window should open. I used the below XML code.

<button id="MyButton" imageMso="HappyFace" onAction="MyBtn_Click" label="MyButton" size="large"/>

In Ribbon load function,

Outlook.Inspectors inspectors;      

  public void Ribbon_Load(Office.IRibbonUI ribbonUI)       

    {                   

inspectors = Globals.ThisAddIn.Application.Inspectors;       

                        this.ribbon = ribbonUI;         

                              }

If I click the button, it should call "MyBtn_Click" which i gave as below,

public void MyBtn_Click(Office.IRibbonControl control)  

{                         

 inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorEvents_ActivateEventHandler(Inspectors_NewInspector);    

 }

Inspectors_NewInspector function:

                  
 void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
        {
            Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
            if (mailItem != null)
            {
                if (mailItem.EntryID == null)
                {
                    mailItem.Subject = "This text was added by using code";
                    mailItem.Body = "This text was added by using code";
                }

            }
        }
     

The problem is, If i click the customized "My Button" in the ribbon it show call  the function "Inspectors_NewInspector"(to open a new mail window with some default subject and body message). But it is not working. Instead I am getting this default subject and body message when i click the "New Mail" button in the Home tab.

I should get this new mail template only when i click the "MyButton" in the ribbon. How can i achieve this?

I am using Outlook 2016, Outlook Add-in.

Thanks in advance.

 

Word memory crash for 32 bit- Large Address Aware

$
0
0

Memory crash issue with 32 bit word vsto.

I am using 32 bit Office-Word for my vsto project. I am trying to call one 32 bit exe which hosted the Chromium Browser using the Xelium.CefGlue with winform.

I had set post build command as below to my exe using the Visual Studio.

call "$(DevEnvDir)..\tools\vsvars32.bat"
editbin /largeaddressaware "$(TargetPath)" 

When I am trying to call from vsto, its still crashing.

I found one link related to excel as below

https://blogs.technet.microsoft.com/the_microsoft_excel_support_team_blog/2016/06/07/excel-2013-and-excel-2016-large-address-aware-updates/

Is there anything available for the Word-2010 ?

How i can set the largeaddressaware attribute to my word application?

Regards

Rajeev Shukla

VS2015 "The project cannot be created" error.

$
0
0

Hi all, 

I have a word document which I have been making some macros for our company's needs. 

I'd like to convert it into a VS Project, but I am unable to create any Office Document projects at all. 

If I try to create an Add-In it works, but a Document-level project, be it importing or creating a new Word Document, invariably results in a non-descriptive "the project cannot be created" error. 

The help link only suggests closing and re-opening Visual Studio, and closing all Office Apps, but the error persists. 

Stuff I have tried: 

Attempting to create the document-level project after a fresh system restart. 

  • Importing the old document (.docx and .docm)
  • Creating a new document (.docx and .docm)

After Repairing the installation of Visual Studio.

After Repairing the installation of MS Office as well.

Notable facts: I have an Office 2016 365 E3 subscription.

VS 2015 Professional is a subscription as well.


The help link does not really address other cases, I don't know any other possible steps to debug it. Any ideas?

Viewing all 5157 articles
Browse latest View live


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