Excel VBA TAPI to blind transfer extension - excel

I have dialed a number using tapirequestmakecall function using Excel VBA.
https://msdn.microsoft.com/en-us/library/ms737210(v=vs.85).aspx
Declare Function tapiRequestMakeCall Lib "tapi32.dll" _
(ByVal stNumber As String, ByVal stDummy1 As String, _
ByVal stDummy2 As String, ByVal stDummy3 As String) As Long
Sub DialNumber(Number As String)
Dim lngStatus As Long
lngStatus = tapiRequestMakeCall(Number, "", "", "")
If lngStatus < 0 Then
MsgBox "Failed to dial number " & Number, vbExclamation
End If
End Sub
I have to transfer the call to extension like 100 after call is connected.
How to do this? Am using TAPI 2.2. Any help would be highly appreciated..

As far as I'm aware, this is not possible. The built-in office TAPI integration is only intended for making an outgoing call with a "1st party"-TAPI driver (a subset of drivers intended for single extension use). Office also limits the access to the API (for "easy" use), hence you do not have access to the normal output of a dial action (= the handle of the created call, to perform further actions).
I would suggest you do not use the built-in office methods but build directly on TAPI (tapi32.dll) itself. Unfortunately, that is a considerably more difficult job.

Related

Why do I have this error : "argument type ByRef not compatible"?

I'm knew to this language.
Okay so, I'm creating a VBA app which aims to manage the distribution of the deifferent courses in a school.
I have this error, which is really "weird" as I really don't understand why I have this even after few research on the web. It says "Argument type ByRef is not compatible". What is really strange with this error is that tt only appends when I define the type of my variable. But if I don't define the type, the it is empty and it makes the function obsolete. HHow do I fix that ?
Private Sub Ajouter(LBConcernee As MSForms.ListBox, Colonne As String, _
Quadrimestre As String, UEnseignement As String)
' This statement is "active" when the user wants to display the courses of the learning unit he chose (Uenseignement)
If UEnseignement = Range("C" & ActiveCell.Row) Then
[...]
End IF
' If the variable is empty, it means that all the courses havve to be displayed and no verification on the learning unit is done
If Uenseignement = ""
[...]
End If
End Sub
This process aims to filter the courses printed on screen by verifying the quadrimester and the Learning Unit of the course. But, with the "as string", I have an error, and without, UEnseignement is empty and it makes my filter completely obsolete as the first condition is never true.
The code and vars are in french (Belgian student) so feel free to ask any complementary infos.
Thanks.
EDIT :
Here is the code that call this sub :
Private Sub Remplir_ListBox(Section As String, ColonneDepart As String, _
ListBoxConcernee As MSForms.ListBox, Bloc As Integer, _
Optional Quadri As String, Optional UESelectionne, _
Optional OptionCompta As String)
Dim CellulePrecedente, ValeurBloc As String
While Range(ColonneDepart & ActiveCell.Row) <> ""
' On ne réécrit pas 2 fois le/la même cours/UE
If CellulePrecedente <> Range(ColonneDepart & ActiveCell.Row) Then
' On ajoute les cours pour le/s bloc/s demandés
If Bloc = 0 Then
Call Ajouter(ListBoxConcernee, ColonneDepart, Quadri, UESelectionnee)
[...]
End If
End If
Wend
End Sub
VBA passes arguments ByRef by default. Meaning, unless you specify ByVal all arguments will be passed ByRef.
There are two ways to pass parameter to a sub or function. (A) ByVal A new variable can be created for use in the sub or function. Initially it's just a copy of the original but if it's modified in the receiving procedure the original doesn't change. (B) ByRef Instead of making a copy, VBA just passes the address of the existing variable. Any changes the subordinate code makes to that variable will be available to the calling procedure. The value of that variable can be changed by the subordinate.
Not all kinds of variables can be passed ByVal. As a rule, VBA requires that all objects must be passed ByRef. So, if you try to pass a ListBox object ByVal VBA will complain. Perhaps, if you turn off Variable declaration, VBA won't bother you with such minor detail and simply refuse to work without explanation.
In your code all arguments are passed ByRef (by default), or so it seems. You can also define an argument to be passed ByVal by enclosing the call in parentheses, like A = 15: MySub (A). We don't see your function call, so this is one possible source of error.
Presuming that this isn't the case I suggest you still focus on the ListBox. It might not be of the MSForm variety. For some reason VBA doesn't seem to be able to pass it ByRef.
The other parameters appear inconspicious. But perhaps there is a mixup in the calling procedure and you are unintentionally assigning the ListBox to one of the strings. In any case, you should look at the interaction between the sub and its caller. There is something wrong in passing the parameters.
UESelectionne is a Variant in the calling sub, but Ajouter expects a String for that argument.

SHA512 hash in Excel

i have a code for generating SHA512 hash of a string in excel, but on some notebook, it runs into error thanks to a net framework related problem. I have came accross a solution recently; when I open the "Me" expression in the locals window, the code can run without any error.
Locals:
Is there any chance to insert an additional code which can expand the "Me" expression in locals when i start running my VBA code in excel?
Sub sha512_kodolas()
Sheets("a").Range("a1").Value = h512(Sheets("b").Range("c1").Value)
End Sub
Function h512(ByVal S As String) As String
'https://msdn.microsoft.com/en-us/library/system.security.cryptography.sha512managed.aspx
Static UTF8 As Object, SHA As Object
Dim Data, Temp, i As Long
If SHA Is Nothing Then
Set UTF8 = CreateObject("System.Text.UTF8Encoding")
Set SHA = CreateObject("System.Security.Cryptography.SHA512Managed")
End If
Data = SHA.ComputeHash_2(UTF8.GetBytes_4(S))
ReDim Temp(LBound(Data) To UBound(Data)) As String
For i = LBound(Data) To UBound(Data)
Temp(i) = Right$("0" & Hex(Data(i)), 2)
Next
h512 = Join(Temp, "")
End Function
could you try this code: https://github.com/krijnsent/crypto_vba -> download the excel and try the ComputeHash_C function? It's also carrying out the SHA512 encryption, but in a slightly different way from yours, so I'm curious to know if it also crashes?
I tried the suggestion from the author above and it works like a charm: "could you try this code: https://github.com/krijnsent/crypto_vba -> download the excel and try the ComputeHash_C function? It's also carrying out the SHA512 encryption, but in a slightly different way from yours, so I'm curious to know if it also crashes?".
Simply clone the Github project, copy the following functions into your Excel workbook:
Function ComputeHash_C(Meth As String, ByVal clearText As String, ByVal key As String, Optional OutType As String) As Variant
Function ConvToBase64String(vIn As Variant) As Variant
Function ConvToHexString(vIn As Variant) As Variant
Function Base64Decode(ByVal base64String)
Function Base64Encode(inData)
It works perfectly well! Thanks for sharing this code!
Using the Excel file from https://github.com/krijnsent/crypto_vba, it works for me if I use commas rather than semicolons in the formula: =ComputeHash_C("SHA512",A3,"","STRHEX"). This is just a small variation on what Luc Krolls has posted.

How to use 'drag n drop' movement on a tabstrip to a form in excel vba?

I have a userform which includes a tabstrip with several tabs. I tried to check if I can change the tabs's order using "drag n drop" movements.
To accomplish this, I tried to check if a TabStrip1_BeforeDropOrPaste event can be fired, while trying to use 'drag n drop' with intention to change a tab's order.
e.g. I tryied to move the fifth tab between the second and the forth with intention to make it the third one.
I used the following piece of code:
Private Sub TabStrip1_BeforeDropOrPaste(ByVal Index As Long, ByVal Cancel As MSForms.ReturnBoolean, ByVal Action As MSForms.fmAction, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer)
MsgBox "event fired!"
End Sub
but the event was not fired. (the messagebox did not show up)
Is there a way to fire the TabStrip1_BeforeDropOrPaste this way? If my approach is completly wrong, any ideas on how to accomplish my goal using another structure?

Excel User-defined functions can't use ArgumentDescriptions in Excel 2007. I'm trying to bypass it in my Add

I have created a couple of user-defined functions in Excel and created a simple add-in so that I can share them with colleagues.
I use Application.MacroOptions in order to give some useful indications for how to use the functions. Especially, I use ArgumentDescriptions to give descriptions for the arguments.
Application.MacroOptions _
Macro:=FuncName, _
Description:=FuncDesc, _
Category:=Category, _
ArgumentDescriptions:=ArgDesc _
HelpFile:= Helpfile
I have just found out that the ArgumentDescriptions parameter is not supported in Excel 2007 and this is causing an error for this version. Excluding this parameter solves the problem.
I don't want to have to distribute two versions of the add-in. I tried to use this code to include the parameter if the version more recent than Excel 2007, but it still gets tripped up on the unrecognized parameter name if used in Excel 2007:
If Left(Application.Version, 2) > 12 Then
Application.MacroOptions Macro:=FuncName, ArgumentDescriptions:=ArgDesc
End If
Is there a way to solve this problem so I can do this all with just one add-in?
Thanks
An easy way to get around the Named argument not found error in the your function is to move the setting of the macro options into 2 separate functions:
If Left(Application.Version, 2) > 12 Then
setUpNewMacroOptions
Else
setUpOldMacroOptions
End If
And then the 2 functions:
Public Sub setUpOldMacroOptions()
Application.MacroOptions Macro:="myMacro", Description:="desc", Category:="cat", HelpFile:="file"
End Sub
Public Sub setUpNewMacroOptions()
Application.MacroOptions Macro:="myMacro", Description:="desc", Category:="cat", ArgumentDescriptions:="blah", HelpFile:="file"
End Sub
As the setUpNewMacroOptions function is never called in Excel 2007, the VBA compiler doesn't try to validate the function so no error.
This procedure works in Excel 2010 with argument descriptiors and in 2007 without them:
Private Sub AddDesc(Macro As String, Description As String, _
Category As String, ArgumentDescriptions As Variant)
#If VBA7 Then 'in Excel 2010 and over
Application.MacroOptions Macro:=Macro, Description:=Description, _
Category:=Category, ArgumentDescriptions:=ArgumentDescriptions
#Else 'in Excel 2007 and under
Application.MacroOptions Macro:=Macro, Description:=Description, _
Category:=Category
#End If
End Sub
Best regards,
Peter Krassoi

EM_SETCUEBANNER sendmessage vb.net usercontrol not working

If I use the code shown below on a vb.net winform the cue banner / watermark appears and behaves as expected (Win7 Pro 32bit VS2008 & 64bit VS2010). However when using the same style of code in a vb.net usercontrol the watermark is not displayed. Anyone got any clues?
Some hours later... This is looking like PEBKAC. Works in a test app. with user controls. Both those created at design time and those loaded at run-time, still doesn't work in the main app. though. Still puzzled. Still looking for a clue.
' Call from form / usercontrol load event handler.
Userhint.WatermarkSet(textbox1, "Some arbitrary text.")
' Noddy library class.
Friend Class Userhint
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>_
Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
ByVal Msg As UInteger, _
ByVal wParam As IntPtr, _
ByVal lParam As String) As IntPtr
End Function
Public Shared Sub WatermarkSet(ByVal ctl As Control, _
byval hintText as string)
const EM_SETCUEBANNER as int32 = &h1501
dim retainOnFocus As IntPtr = new IntPtr(1)
SendMessage(New HandleRef(ctl, ctl.Handle), _
EM_SETCUEBANNER, _
retainOnFocus, _
hintText)
End sub
End Class
Not so much PEBKAC as yet another instance of M$ not documenting things as well as they might.
The short answer is to call Application.EnableVisualStyles() before the Run method.
Application.EnableVisualStyles()
Application.Run()
See questions/7518894/sendmessage-doesnt-work-in-one-project on this site for more info.

Resources