|
Hi all,
I'm trying to write comments in a cell using Automation for Excel 2003. I imported the all Excel Interfaces via VS .NET 2003. All interfaces for excel are based on COleDispatchDriver. I've caught the COleDispatchException but no error description was given. CCOleDispatchException.m_sc = -2146827284.
Ex:
//code has been reduced to bare minimum
//assume all necessary code has been created
CString myCommentText( "Making a statement" );
CRange cell( CWorksheet.get_Range( COleVariant("A1"),COleVariant("A1") ) );
VARIANT comment;
VariantInit( &comment );
comment.vt = VT_BSTR;
comment.bstrVal = myCommentText.AllocSysString();
//error occurs here
//when excel file is viewed, all comments written to it are there
//however the exception occurs when calling the function
cell.AddComment( comment );
SysFreeString( comment.bstrVal );
VariantClear( &comment );
Thank in advance
|
|
|
|
|
I get the same error from VBA. Can't you just trap the error, and if it's 1004, ignore it ?
Steve S
Developer for hire
|
|
|
|
|
I thought about that but I really want to know what is causing it. Besides I don't want to overlook something which may crash the app if left unchecked.
|
|
|
|
|
Currently I've found the solution. Instead of using AddComment, I'll begin using NoteText.
Returns or sets the cell note associated with the cell in the upper-left corner of the range. Read/write String.
Cell notes have been replaced by range comments. For more information, see the Comment object.
CRange .NoteText(Text, Start, Length)
expression Required. An expression that returns a Range object.
Text Optional Variant. The text to add to the note (up to 255 characters). The text is inserted starting at position Start, replacing Length characters of the existing note. If this argument is omitted, this method returns the current text of the note starting at position Start, for Length characters.
Start Optional Variant. The starting position for the text that's set or returned. If this argument is omitted, this method starts at the first character. To append text to the note, specify a number larger than the number of characters in the existing note.
Length Optional Variant. The number of characters to be set or returned. If this argument is omitted, Microsoft Excel sets or returns characters from the starting position to the end of the note (up to 255 characters). If there are more than 255 characters from Start to the end of the note, this method returns only 255 characters.
|
|
|
|
|
i wanna contruct a safearray,which is made up of VARIANT type element,which vt = VT_BSTR;i use SafeArrayCreate to create the safearray,then use SafeArrayPutElement to add element into array one by one,it's ok,and (this is just my test code) if i use SafeArrayGetElement to get the element that just now put into the array,on the neck of the SafeArrayPutElement at the same cycle statement,it's all right.
but if i write the SafeArrayGetElement out of the same cycle,the program
crashed.why?it's so strange.
my codes are as follows:
VARIANT *pvarCis = new VARIANT[nCount];
for(int i = 0;i < nCount;i++)
{
CComBSTR bstrCi(arCi.GetAt(i));
(pvarCis + i)->vt = VT_BSTR;
(pvarCis + i)->bstrVal = bstrCi.Copy();
}
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = nCount;
SAFEARRAY * psa = NULL;
psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
if(psa)
{
psa->cbElements = nCount;
VARIANT *pvarCellInfo = new VARIANT[nCount];
HRESULT hresult;
for(long lIndex = 0; lIndex < nCount; lIndex++)
{
hresult = SafeArrayPutElement(psa,&lIndex,&pvarCis[lIndex]);
if(FAILED(hresult))
return;
hresult = SafeArrayGetElement(psa,&lIndex,&pvarCellInfo[lIndex]);
if(FAILED(hresult))
return;
}
for(lIndex = 0;lIndex < nCount; lIndex++)
{
hresult = SafeArrayGetElement(psa,&lIndex,&pvarCellInfo[lIndex]);
if(FAILED(hresult))
return;
}
... ...
}
|
|
|
|
|
cbElements must equal the size of an element of the array. Try with:
psa->cbElements = sizeof(<code>VARIANT</code>);
"no xe tuto oro quel che luse"
rechi+
|
|
|
|
|
Hello XPointer,
I tried your sample source code and discovered that the error lies around the following lines :
if(psa)
{
//psa->fFeatures = FADF_VARIANT;
psa->cbElements = nCount; // <-- should not set cbElements.
...
...
...
The "cbElements" field is already set when you called the SafeArrayCreate() function earlier :
psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
Furthermore, this field indicates the size of each element of the array and since the element type has been declared to be VT_VARIANT, "cbElements" should be sizeof(VARIANT), i.e. 16 bytes, and should not be "nCount".
However the fields of the SAFEARRAY struct (including fFeatures) should all be transparent to developers and should only be accessed via APIs and not modified or accessed individually.
I suggest commenting out the line :
psa->cbElements = nCount;
Your code should work fine thereafter.
Best Regards,
Bio.
|
|
|
|
|
Hope this helps.. this creates a variant made of a safe array of variant which themselves are strings!
Just ignore the last 3 lines of code!
void CVariantTools::ToVariant(VARIANT & var,const CStringArray & arrColumns)
{
// Create the array
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = arrColumns.GetSize();
SAFEARRAY FAR* pArrayCol = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
// Fill it with the column property
for ( int nCol=0; nCol < arrColumns.GetSize(); nCol++)
{
long rgIndice=nCol;
COleVariant oleValue(arrColumns.GetAt(nCol),VT_BSTR);
SafeArrayPutElement(pArrayCol,&rgIndice,&oleValue);
}
// Prepare the variants
VariantClear(&var);
var.vt=VT_ARRAY|VT_VARIANT;
var.parray = pArrayCol;
}
|
|
|
|
|
thanks Bogdan Rechi, Lim Bio Liong and BadJerry ,
now i complete my src according to your advice,thanks.
btw,i just considerred 'the Size of an element' to 'the number of elements' by mistake,so the error occurred certainly.it's my carelessness
thanks a lot!!!
|
|
|
|
|
Hi guys,
I've got a ASP .Net application which uses a COM object. I've turned on impersonation and assigned a valid windows user. The system.security.principle.windowsidentity.getcurrent.name property correctly returns the logon user.
However, the COM is still running under the ASPNET identity. I know this because I've added a function in the COM object to return the current user(win32 API).
How do I overcome this problem? The COM object needs to run under a non ASPNET account in order for it to access another server.
Thanks.
|
|
|
|
|
I am attempting to create a class using C# or C++ that can be called from Visual Basic for Applications in Excel. I have tried several examples from CodeProject, Microsoft, and others, but whether I use the regasm utility or check the C# compiler option "Register for COM Interop", I get a message to the effect that there are no types that can be registered for COM Interop. I must be missing something obvious... any suggestions?
|
|
|
|
|
RegAsm registers any types that are public, do not have the ComVisible(false) attribute applied, and have a default constructor (one which takes no arguments). Also, any types used as parameters must be Automation-compatible. Any classes that are used as parameters must also conform to these requirements.
|
|
|
|
|
Thanks for the info. The Microsoft article does not mention the ComVisible attribute, which is obvious now that you've pointed it out. However, now I have another problem, which is that, when I select the add-in in the Automation Servers dialog box (Tools/Add-Ins/Automation Servers) in Excel, I get a message to the effect that it can't find mscoree.dll. That file's directory (C:\WINDOWS\system32) is included in the PATH environment variable, so it should be findable. Even copying mscoree.dll into the Excel application, add-in, or library directories does not help. Any suggestions?
|
|
|
|
|
Thanks for the info. The Microsoft article does not mention the ComVisible attribute, which is obvious now that you've pointed it out. However, now I have another problem, which is that, when I select the add-in in the Automation Servers dialog box (Tools/Add-Ins/Automation Servers) in Excel, I get a message to the effect that it can't find mscoree.dll. That file's directory (C:\WINDOWS\system32) is included in the PATH environment variable, so it should be findable. Even copying mscoree.dll into the Excel application, add-in, or library directories does not help. Any suggestions?
|
|
|
|
|
Hi,
I am building a word document using C# and Word .NET Programmability however I have a question that I cannot find the answer for.
I have designed the Word template with embedded bookmarks.
When I build the document I dynamically place text at each book mark position.
The base document also has some other fixed text in it.
However in the completed document the original text is always moved.
EG:
Original document
MyText More MyText
Completed document
MyText [C# Added Text] More MyText
It seems that the original text is moved along a number of tab spaces.
Is there anyway to prevent this so that the layout of the completed document is the
same as the original (the only difference is the added text)?
I know that the spaces I left in the template are sufficient for the text I want to add.
Any help/advice greatly appreciated.
Regards Andrew
|
|
|
|
|
Move your range to Range.Characters.Last and then try inserting text through c#. this will insert the text at EOD
Hope this helps
--------------
Pavan Kulkarni
|
|
|
|
|
Hello,
I have Visual C++ program that implements Graphical User Interface (GUI). This program uses CWinApp, CFormView, CFrameWnd, and CDocument.
Now I need to package this C++ application to work as COM DLL (or ActiveX).
This program must be used as popup window from another program written in Java.
Is it possible to convert Visual C++ program with GUI into COM DLL or ActiveX ?
|
|
|
|
|
Hi all,
I have a problem in identifying which click was pressed.
Iam building two groups A and B.Each group contains one textbox and add button(all are builded dynamically).If i click on add button it should add textboxes to respective group.For add button click iam adding attributes and incrementing value from javascript using a hidden variable.
btnAddRange.Attributes.Add("onclick","javascript:submitVIN('"+GroupId+"')") this is code for click on a button.How can we identify click is performed on respective group.
Any help is greatly appreciated.
Thanks,
Vijaya
vijaya
|
|
|
|
|
which application it is??(MFC APP)
|
|
|
|
|
Hi,
I have a dll file that has implemented in framework 2.0 (VS 2005), but it has not used any advanced libraries. It is a vs2003 project, but have opened in VS2005. I have lost the code, what i have only the dll and now i want to add it to a vs2003 project. But it does not allow me to add it as a referrence. The problem is, it is a 2005 file.
Can I convert the dll to framework 1.1???????
Thanks in advanced!
jayasshc
|
|
|
|
|
Hi all.
I am having a problem passing a SAFEARRAY of IDispatch pointers to an outproc server. The problem occures when the outproc server goes to access one of IDispatch Interfaces method. The code work fine in inproc server.
Thanks in advance.
satindar
|
|
|
|
|
Hello satindar_kumar,
Make sure that the type library of the original interface (which contains the method that takes the SAFEARRAY of IDispatch pointers as parameter) is registered properly. Also make sure that the type library(ies) of each of the interfaces contained inside the SAFEARRAY is/are registered properly.
The type libraries must be registered because marshaling will definitely be required if the server is outproc.
In the case of inproc server, marshaling may not be needed hence the code worked fine. However, take note that if the interface is accessed cross-apartment, then marshaling will be required and hence the type libraries will need to be properly registered.
Hope the above helps,
Bio.
|
|
|
|
|
Good day. I am busy try to build an install for my project using WixEditor. I am struggling as this project has Dlls and one of these Dlls runs a CategoryInstaller that load Counter to a machine during the install. Can anyone point me to the right direction as to how to use Wix and how to reference DLLs and all, using Wix
Thanks
Kulile --- RSA
|
|
|
|
|
Did you mean a PerformanceCounterInstaller member?
WiX is the Windows Installer XML toolset. It doesn't really know much about what Visual Studio's deployment projects are up to. The .NET XxxInstaller classes seem to be intended for use with Visual Studio's deployment projects, which include Custom Action DLLs in your package which load the framework and run the Installer class.
WiX includes a performance counter custom action[^]. To use this, you need to create a .h and .ini file containing the descriptions of your performance counters. However, I don't know how to get this out of the Framework.
You may get a better answer by asking on the wix-users[^] mailing list.
|
|
|
|
|
Hello, everyone.
Please see below the description of a problem I met:
1. The Goal
The goal is to open the MS Excel document in read-only mode (so that it will be accessible for users while it is in use by my application). The access to the document is performed using COM. The application is written in VC++ using ATL.
2. The problem.
The "Open" method of the Workbooks object receives 13 parameters: the first is required (the path to the document), the others are optional.
The third parameter is ReadOnly, i.e. the parameter which controls the mode (r- or rw).
Therefore, to open a document in rw mode I have to pass only one (first parameter) - and it works fine.
But if I decide to open it in r- mode I will need to pass all 13 parameters. And here is there the problem occurs: I can not get IDispatch for a document if I pass all parameters.
Ok, I'm a not a lazy guy . I tried following options:
1) all parameters except 1-st and 3-d were passed as VT_EMPTY
2) all parameters except 1-st and 3-d were passed as VT_NULL
3) all parameters except 1-st and 3-d were initialized with the neutral values (which I got from the MS Excel Help for VB programming).
In all cases the result was the same: I got VT_EMPTY in the resulting VARIANT (please note, that the only thing I had to do, in order to open a document - change the number of parameters from 13 to 1).
Frankly speaking, I'm in the dark...
Have you ever met such problem? Could you please advice, where I'm wrong (since there is no doubt that I am)?
Your help is much appreciated. Thank you very much in advance.
|
|
|
|
|