excel 2010 add-in setup project with setup factory - excel

I am developing an excel add-in. I have serial numbers(ex. 100 psc) and I want to check when excel add-in installing on pc. But I cant do it with VS2010 setup project because it is not supporting serial number list storing and checking.
so I want to do this with setup factory and I did it like this link:
link
but I have a problem excel ;
if I select "Yes", excel working for opening .dll, if select "No", it do anything.
and my setup factory list like this.
and my setup factory "on post install script", my Addinfilename value is "Posta Guvercini Excel AddIn For 2010.dll"
-- Determine registry key (2 = HK CURRENT USER)
sVersions = Registry.GetKeyNames(2, "Software\\Microsoft\\Office");
-- Iterate through the registry keys per MS Office-version
--Next line has SetupFactory 8 code
--for iCount1, sVersion in sVersions do
for iCount1, sVersion in pairs(sVersions) do
-- Try opening the registry key
sSubKey = "Software\\Microsoft\\Office\\"..sVersion..
"\\Excel\\Options\\"
sValues = Registry.GetValueNames(2, sSubKey);
--initialize index counter
iIndex = -2
if sValues then
--Determine the index of the maximimum OPEN registry entry
--Next line has SetupFactory 8 code
--for iCount2, sValue in sValues do
for iCount2, sValue in pairs(sValues) do
if (String.Left(sValue, 4) == "OPEN") then
--Check whether the user did not already install
--the same add-in to prevent errors when opening Excel
sKeysValue = Registry.GetValue(2, sSubKey, sValue, true)
if String.Find(sKeysValue, SessionVar.Expand(
"%AddinFileName%"), 1, false) > 0 then
iIndex = -1
-- leave loop
break;
else
if (sValue == "OPEN") then
iIndex = 0
else
iIndex = String.ToNumber(String.Mid(
sValue, 5, String.Length(sValue)-4))
end;
end;
end;
end;
-- -1 means: This add-in is already installed; we're done
if iIndex ~= -1 then
--Determine path based on variable "%AddinFileName%
sAppPath = String.Char(34)..
SessionVar.Expand("%AppFolder%")..
"\\"..
SessionVar.Expand("%AddinFileName%")..
String.Char(34)
-- -2 is the initialized value of the index counter
if (iIndex == -2) then
-- OPEN-key does not exist
Registry.SetValue(2, sSubKey, "OPEN",
sAppPath, REG_SZ)
else
Registry.SetValue(2, sSubKey, "OPEN"..(iIndex + 1),
sAppPath, REG_SZ)
end;
end;
end;
end;

Looks like you are building an Automation addin. If so you need to prefix the addin name with /A to tell Excel that its an automation addin. otherwise its expecting an XLL or an XLA or an XLAM

i solve this problem. When doing excel installiation, we must use registry record.
result = Registry.SetValue( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Office\\Excel\\Addins\\company" , "LoadBehavior" , "3" , REG_DWORD );
result = Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Office\\Excel\\Addins\\company" ,"FriendlyName", "program name", REG_SZ);
result = Registry.SetValue( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Office\\Excel\\Addins\\company" , "Description" , "program name" , REG_SZ );
result = Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Office\\Excel\\Addins\\company" ,"Manifest", SessionVar.Expand("%AppFolder%\\myvtofile.vsto|vstolocal"), REG_SZ);
for add-in start when excel startup.
LoadBehavior key's value should be "3".

Related

AHK open excel workbook and repair

hi can anyone help me with the below code, i have an excel sheet that i need to open and repair then save, i do this because it tends to break atlot. any help much appreciated
; Open the Excel document
xlApp := ComObjCreate("Excel.Application") ; create a (new) instance of Excel
xlApp.Visible := true ; make Excel visible
xlApp := ComObjActive("Excel.Application") ; make Excel active
xlApp := xlApp.Workbooks.Open("C:\Users\Phill\Desktop\New Microsoft Excel Worksheet.xlsx", CorruptLoad := XlCorruptLoad.xlRepairFile)
xlApp := "" ; clear the variable
return
There are two issues here:
AHK doesn't support named parameters for COM
AHK doesn't know what XlCorruptLoad.xlRepairFile means
Solutions:
Based on the AHK documentation, use commas with nothing between to send the value in the proper position for CorruptLoad. According to the Microsoft documentation, it's the last of 15 parameters.
The value for XlCorruptLoad.xlRepairFile is 1, so that's what you'd pass in for that parameter.
Here is the full (untested) code:
; Open the Excel document
xlRepairFile:= 1
xlApp := ComObjCreate("Excel.Application") ; create a (new) instance of Excel
xlApp.Visible := true ; make Excel visible
xlApp := ComObjActive("Excel.Application") ; make Excel active
xlApp := xlApp.Workbooks.Open("C:\Users\Phill\Desktop\New Microsoft Excel Worksheet.xlsx", , , , , , , , , , , , , , xlRepairFile)
xlApp := "" ; clear the variable
return

MS Access: how to delete everything in a string after two specific characters

How can I delete the number together with the space in a string while my data looks like this:
randomtext = 567897
otherrandomtext = 3827475
evendifferentone : 483838
andsoon : 03948
type of contact 594837
other type of contact 453222223
so that it can look like this:
randomtext
otherrandomtext
evendifferentone
andsoon
type of contact
other type of contact
I managed to use update query (written below) to remove everything after "=" but how to update both (with "=" and ":") at the same time?
UPDATE [MyTable]
SET [Name] = Left([Name], InStr([Name], "=") - 1)
WHERE [Name] Like "*=*"
I can do it in two separate queries while it is only data with "=" or ":", but I don't know how to handle it when I have also data like "type of contact 594837". Maybe there is a way to just delete everything that is a number, = and : sign?
Fairly simply.. You can write a VBA function that you can actually embed in your SQL queries to do this. I went to Database Tools (Top of MS Access), Visual Basic, Right Click on the Modules Folder, Insert -> Module. After you write/copy the code, go to Debug at the top of the Visual Basic for Applications IDE and click "Compile YourDatabaseName.
See below:
Option Compare Database
Option Explicit
Public Function TrimString(fieldToTest As Variant) As Variant
Dim test, test2 As Variant
Dim trm As Variant
Dim intSearch, lngth As Integer
TrimString = Null
test = InStr(fieldToTest, "=")
test2 = InStr(fieldToTest, ":")
lngth = Len(fieldToTest)
If test > 0 Then
'We know it contains an equals sign
trm = Left(fieldToTest, test - 1)
trm = Trim(trm)
Debug.Print trm
ElseIf test2 > 0 Then
'We know it contains a colon
trm = Left(fieldToTest, test2 - 1)
trm = Trim(trm)
Debug.Print trm
ElseIf lngth > 0 Then
'Find out if it has integers in it
'Rebuild the string without Integers
For intSearch = 1 To lngth
If Not IsNumeric(Mid$(fieldToTest, intSearch, 1)) Then
trm = trm & Mid$(fieldToTest, intSearch, 1)
Else
End If
Next
trm = Trim(trm)
Else
'Regular String
'Do Nothing
trm = fieldToTest
End If
TrimString = trm
End Function
There's not very much error handling, but I think this answers your question.
I threw it in a Table, field data type is Text:
Table
ID stringTest (Field Name)
1. randomtext = 123453
2. otherrandmtext = 543555
3. evendifferentone : 453553
4. andsoon : 05453534
Output :
ID Expr1
1. randomtext
2. otherrandmtext
3. evendifferentone
4. andsoon
SQL :
SELECT Table2.ID,
TrimString([stringTest]) AS Expr1
FROM Table2;
Recall from the VBA code that TrimString is the function name.
If there is anything I overlooked - please let me know and I will do my best to correct it.

Assign contents of Excel cell to string variable in AutoIT [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am writing a script that I want to pull cell values from an Excel spreadsheet containing usernames and passwords. I wish to use two variables USERNAME and PASSWORD. I would like to use the data on each row and move down a row with each pass of the loop.
I have looked over Excel UDF included in AutoIT and ExcelCOM_UDF written by a third party. I cannot seem to find the answers I am looking for. This should be a very basic function of either of these, but I am having trouble.
I am not looking for a handout, so just a nice reference page is fine. BUT if you have a snippet of what I need, it will not hurt my feelings as I am not determined to write this code solely on my own.
My "A" column will contain the USERNAME variables, and the "B" column will contain my PASSWORD variables.
Added snippet of some code of what I have so far. I have not tried to pull anything from Excel yet, because I cannot find a command that seems to do what I am looking to do. Hopefully seeing the code will give a better picture of my goal.
I DO NOT WISH TO MODIFY THE SPREADSHEET PROGRAMMATICALLY, ONLY SET STRING VARIABLES FROM CELL TEXT.
...
$USERNAME = "usernameHere" ;I want to set this variable as the text from A1 of c:\test.xls
$PASSWORD = "passwordHere" ;I want to set this variable as the text from B1 of c:\test.xls
;Username Box
MouseClick("left",1179,488,1)
;Type username
Send($USERNAME)
;Password Box
MouseClick("left",1179,578,1)
;Type Password
Send($PASSWORD)
...
In order to read a spreadsheet containing a list of usernames and password. This function create an array with two dimensions. The first column contains usernames, the second the password. With this
#include <Array.au3>
#include <Excel.au3>
Func get_data_Excel($filePathExcel)
Local $error
Local $oExcel = _ExcelBookOpen($filePathExcel, 0)
$oExcel.Application.DisplayAlerts = False
$oExcel.Application.ScreenUpdating = False
$error = Int(#error)
Select
Case $error = 1
msgbox(16, "Erreur : Fermeture de l'application", "Code erreur _ExcelBookOpen : 1"&#CRLF&#CRLF&"Impossible de creer l'objet $oExcel avec _ExcelBookOpen")
Case $error = 2
msgbox(16, "Erreur : Fermeture de l'application", "Code erreur _ExcelBookOpen : 2"&#CRLF&#CRLF&"Impossible d'ouvrir le fichier "&$filePathExcel&" avec _ExcelBookOpen")
EndSelect
If $error > 0 Then
_ExcelBookClose($oExcel, 0) ; Close without save
Exit
EndIf
; Read column A (login) and column B (pwd)
_ExcelSheetActivate($oExcel, "sheet1")
$nb_columns = $oExcel.ActiveSheet.UsedRange.Columns.Count
$nb_rows = $oExcel.ActiveSheet.UsedRange.Rows.Count
Local $array_data_excel[$nb_rows][2]
Local $idx
For $idx = 0 To $nb_rows-1
$array_data_excel[$idx][0] = $oExcel.Activesheet.Cells($idx+1, 1).Value
$array_data_excel[$idx][1] = $oExcel.Activesheet.Cells($idx+1, 2).Value
Next
_ExcelBookClose($oExcel, 0)
_ArrayDisplay($array_data_excel, "Data from excel file")
EndFunc
And to use this function :
get_data_Excel("d:\users.xlsx")
#include <Excel.au3>
Local $MyUsernameArray[5] = [ "Hans", "Gerd", "Walter", "Klaus", "Peter" ] ;Your Username Array
Local $MyPasswordArray[5] = [ "12345", "I", "am", "so", "creative" ] ;Your Password Array
$oExcel = _ExcelBookNew(1) ;Set this to 0 if you want it to work in background
_ExcelWriteCell ( $oExcel, "Usernames", "A1" ) ;self explaining (i hope)
_ExcelWriteArray ( $oExcel, 2, 1, $MyUsernameArray ,1) ;^
_ExcelWriteCell ( $oExcel, "Passwords", "B1" );^
_ExcelWriteArray ( $oExcel, 2, 2, $MyPasswordArray ,1);^
_ExcelBookSaveAs($oExcel, #ScriptDir & "\PleaseAtleastPostSomeCodeNextTimeSoWeSeeYouTried", "xls") ;save the file
_ExcelBookClose($oExcel, 1, 0) ;exit and save
If you want to get all control with COM/Automation Excel, don't use the UDF , andd deep inside the Com/Automation with the function AutoIt ObjCreate. With this function you can get the control of the Object Excel in AutoIt
COM/Automation with Excel
1) Create reference on COM Object of target application (here this is Excel)
$oExcel = ObjCreate("Excel.Application")
2) Add some options on this instance
With $oExcel
.Visible = 1
.WorkBooks.Add
EndWith
3) And now the work can be begin (add some worksheet or data, save the workbook...)
With $oExcel
.ActiveWorkbook.Worksheets(1).Name = "SHEET_ONE"
.ActiveWorkbook.Worksheets(1).Cells(1,1) = "I believe i can fly !!!"
EndWith
Hacks 1 : Save As
; Create new file with one sheet named "SHEET_ONE"
Local $oExcel = ObjCreate("Excel.Application")
With $oExcel
.SheetsInNewWorkbook = 1
.Visible = 1
.WorkBooks.Add
.ActiveWorkbook.Worksheets(1).Name = "SHEET_ONE"
.ActiveWorkbook.Worksheets(1).Cells(1,1) = "I believe i can fly !!!"
EndWith
Local $filename = #WorkingDir&"\saveas_excel.xls"
$oExcel.Application.DisplayAlerts = 0
$oExcel.Application.ScreenUpdating = 0
$oExcel.ActiveWorkBook.SaveAs($filename, 1, Default, Default, Default, Default, 2, 1)
$oExcel.Quit
More information (in french) on http://www.autoitscript.fr/forum/viewtopic.php?t=3272&f=11

Update cell query for Excel ADO from Delphi

I have the following code to open my Excel Worksheet, using TADOConnection and TADOQuery:
conExcel.ConnectionString := 'Provider=Microsoft.JET.OLEDB.4.0;Data Source="D:\temp\file.xls";Extended Properties="Excel 8.0;HDR=No"';
conExcel.Connected := true;
When I run the following code:
queryExcel1.SQL.Text := 'SELECT * FROM [Hoja1$]';
queryExcel1.Open;
while not queryExcel1.eof do
begin
showmessage(queryExcel1.Fields.Fields[0].AsString);
queryExcel1.Next;
end;
I get each line of the file, so it is working ok, but I want to update a cell.
I am using this code:
queryExcel2.SQL.Text := 'UPDATE [Hoja1$] SET F1 = 555555';
queryExcel2.ExecSQL;
Which somehow updates every "A" cell on the worksheet to 555555, but what I really want is to just set the A1 cell to 555555. Any hints on how to include the WHERE section of the query. Thanks.
If you want to use an Adoquery you will have to set ParamCheck to false, since you will have to use : for the range you want to update.
An other option would be to use the connection directly.
In the example below the range B2:B2 is used with F1 which is the default name of Jet for the first column. (B2 is the cell we want to update)
Q.SQL.Text := 'UPDATE [Hoja1$B2:B2] SET [F1] = 555555';
Q.ExecSQL;
// or:
//AdoConnection1.Execute('UPDATE [Hoja1$B2:B2] SET [F1] = 555555');

Oracle Forms using OLE2 not saving Excel document on 3-tier setup

System setup:
3-Tier environment
Client Machine - doesn't matter
Web-Tier - Not sure. Probably Windows Server 2008 64 bit
-Jdk 7u3
App Server - Windows Server 2008 64 bit
-Weblogic Server 10.3.6
-Excel 2010
-Jdk 7u3
Database Server - Not sure. Probably Windows Server 2008 64 bit.
-Oracle Database 11g
Programming using Oracle Forms 11.1.1.6
Now, my problem is that when we had designed they system, everything but the database was on one PC. I was able to read and write Excel documents no problem at all. Then we moved everything to a tiered setup where we had the client, app server and database server. Everything still worked great. Finally they set up the 3-tiered system and that's where I ran into my problems.
When I have Oracle Forms write to the Excel document the code appears to execute without any errors until I try to copy the file from the App Server using Webutil.
PROCEDURE Export_to_Excel IS
-- Declare the OLE objects
application OLE2.OBJ_TYPE;
workbooks OLE2.OBJ_TYPE;
workbook OLE2.OBJ_TYPE;
worksheets OLE2.OBJ_TYPE;
worksheet OLE2.OBJ_TYPE;
--cell OLE2.OBJ_TYPE;
range OLE2.OBJ_TYPE;
range_col OLE2.OBJ_TYPE;
-- Declare handles to OLE argument lists
args OLE2.LIST_TYPE;
p_filename VARCHAR(255);
--p_file TOOL_RES.RFHANDLE;
p_file Text_IO.File_Type;
p_filename_client VARCHAR2(500);
v_filename VARCHAR2(500);
v_error VARCHAR2(500);
passed_filename VARCHAR2(500);
BEGIN
-- Retrieve user specific directory to create new file in
p_filename := Webutil_file_transfer.get_work_area;
-- Start Excel
application:=OLE2.CREATE_OBJ('Excel.Application');
-- Return object handle to the Workbooks collection
workbooks:=OLE2.GET_OBJ_PROPERTY(application, 'Workbooks');
-- Add a new Workbook object to the Workbooks collection
workbook:=OLE2.GET_OBJ_PROPERTY(workbooks,'Add');
-- Return object handle to the Worksheets collection for the Workbook
worksheets:=OLE2.GET_OBJ_PROPERTY(workbook, 'Worksheets');
-- Set up the Header worksheet
args:=OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 1);
worksheet:=OLE2.GET_OBJ_PROPERTY(worksheets,'Item',args);
OLE2.DESTROY_ARGLIST(args);
OLE2.set_property(worksheet,'Name','Header');
-- Build header form
populate_header(worksheet);
-- Autofit columns
range := OLE2.GET_OBJ_PROPERTY( worksheet,'UsedRange');
range_col := OLE2.GET_OBJ_PROPERTY( range,'Columns');
OLE2.INVOKE( range_col,'AutoFit' );
OLE2.RELEASE_OBJ( range );
OLE2.RELEASE_OBJ( range_col );
-- Set up the Item worksheet
args:=OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 2);
worksheet:=OLE2.GET_OBJ_PROPERTY(worksheets,'Item',args);
OLE2.DESTROY_ARGLIST(args);
OLE2.set_property(worksheet,'Name','Item List');
-- Build Item sheet
populate_item_sheet(worksheet);
-- Delete the last worksheet that excel automatically creates
args:=OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(args, 3);
worksheet:=OLE2.GET_OBJ_PROPERTY(worksheets,'Item',args);
OLE2.DESTROY_ARGLIST(args);
OLE2.invoke(worksheet, 'Delete');
-- Save as worksheet
OLE2.SET_PROPERTY(application,'DisplayAlerts',FALSE);
IF p_filename is not null THEN
args := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG( args, p_filename || :PARAMETER_B1.FILENAME || '.xlsx');
OLE2.ADD_ARG( args, 56 );
OLE2.INVOKE( workbook,'SaveAs',args );
OLE2.DESTROY_ARGLIST( args );
END IF;
-- Close workbook
OLE2.INVOKE( workbook ,'Close');
-- Release the OLE objects
OLE2.RELEASE_OBJ(worksheet);
OLE2.RELEASE_OBJ(worksheets);
OLE2.RELEASE_OBJ(workbook);
OLE2.RELEASE_OBJ(workbooks);
OLE2.INVOKE(application, 'Quit');
OLE2.RELEASE_OBJ(application);
--Check if file was writen correctly
p_file := text_io.fopen(p_filename || :PARAMETER_B1.FILENAME || '.xlsx','r');
Text_IO.Fclose(p_file);
--Added the following code
passed_filename := :PARAMETER_B1.FILENAME || '.xlsx';
v_filename := p_filename || passed_filename;
-- Popup a dialog box to allow user to select the location to save the file
p_filename_client := CLIENT_GET_FILE_NAME ( 'C:\', passed_filename, NULL, 'Select A Directory', SAVE_FILE, FALSE );
if p_filename_client is null then
message ('Creation of the spreadsheet has been canceled.');
raise form_trigger_failure;
end if;
-- File Transfer to Client
PROCESS_COMM_FILE_CLIENT.FILE_TRANSFER('O', p_filename_client, v_filename, null, v_error);
EXCEPTION
WHEN others THEN
Text_IO.Fclose(p_file);
message( SQLERRM( SQLCODE ) ) ;
if p_filename_client is not null then
MESSAGE('An error occurred while creating file.');
end if;
END;
The code fails at the FILE_TRANSFER because the form does not get created on the App Server like it is supposed to.
A related problem that is occuring is that when I try to upload the excel document and read it in to oracle I get a ORA-305500 error. I have tried to have the DBA uninstall and reinstall Excel and made sure all of the features/add-ons were included during the installation but the problem still hasn't been fixed.
Could someone please give me some suggestions on what to do to fix this problem or continue to problem shoot this?
Thanks,
Bill
If the problem relates to the actual generation of the file using OLE, then I would sugest that you create the directory:
C:\Windows\System32\config\systemprofile
The OLE code in Oracle Forms checks in this directory for OLE configuration settings. It doesn't matter if the directory is empty, only that it exists!
Check your $ORACLE_HOME/forms/server/webutil.cfg, if there is any restriction in reading directories.
Basically, check the parameters "transfer.appsrv.read.<n>=/.../.../".
If I am understanding your problem, you intend to save the file in the client machine. Now assuming you are using WEB_FORMS (i.e. you use a web browser to access forms application), you can use the code below to save the file from AS to client machine, instead of PROCESS_COMM_FILE_CLIENT.FILE_TRANSFER. The OLE objects create the file at the AS, you need to get the file from AS (App server) to local machine-
l_success := webutil_file_transfer.AS_to_Client_with_progress
(clientFile => 'c:\fine.xlsx'
,serverFile => 'c:\data\file.xlsx'
,progressTitle => 'Save file in progress'
,progressSubTitle => 'Please wait');
if l_success then
message('File saved successfully');
else
message('Cannot save file');
end if;
The abve code should show a "Save file in progress" pop up box with progress bar to show that your file is being saved to local machine.

Resources