APi not working in Xlspadlock

Golfer65

New member
Support please can link this as this is not an workbook open event but an APi Im trying to get to work with your software. You may close the other open event as its an API issue thanks
5_f40856482fe1e45ac8f1605885140a2d.png
Does Workbook open event work in compiled workbook? XLS Padlock
Ok here is my code Support. My Icon is “Icon.ico”-Thank you Sub ChangeExelIcon() 'Get the icon handle. 'You can use the full path of the icon file, i.e.: hwndIcon = ExtractIconA(0, "C:\Users\Christos\Desktop\MyApp\Icon.ico", 0) 'Or the icon path relative to the current workbook, i.e.: 'hwndIcon = ExtractIconA(0, ThisWorkbook.Path & "\$SIGN.ico", 0) 'Check if the icon handle is valid. If hwndIcon <> 0 Then 'Change the icon. 'For a big icon (32 x 32 pixels), use this line: 'SendMe…
This is the Excel macro -it works flawlessly in Excel but not in your software

Sub ChangeExelIcon()

'Get the icon handle.
'You can use the full path of the icon file, i.e.:
hwndIcon = ExtractIconA(0, “C:\Users\Christos\Desktop\MyApp\Icon.ico”, 0)
'Or the icon path relative to the current workbook, i.e.:
'hwndIcon = ExtractIconA(0, ThisWorkbook.Path & “$SIGN.ico”, 0)

'Check if the icon handle is valid.
If hwndIcon <> 0 Then
Code:
'Change the icon.
'For a big icon (32 x 32 pixels), use this line:
'SendMessageA Application.HWnd, WM_SETICON, ICON_BIG, hwndIcon
'For a small one (16 x 16 pixels), use the next line (typical case):
SendMessageA Application.hWnd, WM_SETICON, ICON_SMALL, hwndIcon

'Inform the user.
'MsgBox "Excel icon was changed successfully!", vbInformation, "Done"
End If

We tried the following without any luck

Option Explicit

Declare Function FindWindow Lib “user32” Alias “FindWindowA” (ByVal ClassName As String, ByVal WindowName As String) As Long

Declare Function ExtractIcon Lib “shell32.dll” Alias “ExtractIconA” (ByVal Instance As Long, ByVal ExeFileName As String, ByVal IconIndex As Long) As Long

Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal hWnd As Long, ByVal Message As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long

Const WM_SETICON = &H80

Public Function PathToFile(filename As String)

Dim XLSPadlock As Object

On Error GoTo Err

Set XLSPadlock = Application.COMAddIns(“GXLSForm.GXLSFormula”).Object

PathToFile = XLSPadlock.PLEvalVar(“EXEPath”) & filename
Exit Function

Err:

PathToFile = “C:\Program Files\Test\Test.exe & $SIGN.ico”

End Function

Public Sub SetExcelIcon(ByVal IconPath As String)

Dim A As Long

Dim hWnd As Long

Dim hIcon As Long

hWnd = FindWindow(“XLMAIN”, Application.Caption)

hIcon = ExtractIcon(0, IconPath, 0)

If hIcon > 1 Then

Call SendMessage(hWnd, WM_SETICON, True, hIcon)

Call SendMessage(hWnd, WM_SETICON, False, hIcon)

End If

End Sub

Public Sub ChangeExcelIcon()

Dim file_name As String

file_name = “$SIGN.ico”

Call SetExcelIcon(“C:\Program Files\Test$SIGN.ico”)

I went back to my original macro and only tried pathtofile instead of Thisworkbook.Path but Im getting an error argument not optional

This is now 6 days and I cannot make this api work which work in all versions of excel

here is the code I tried that argument not optional error

Sub ChangeExcelIcon()
Code:
'The call below works fine when you explictly define the path to the file

'Call SetExcelIcon(“C:\Users\Christos\Desktop\MyApp\Icon.ico”)

'If you want to use excel’s “ThisWorkbook.path” you would need to

'call XLS function as described below.

'this line would have to be changed to call XLS Function PathToFIle

'hwndIcon = ExtractIconA(0, ThisWorkbook.Path & “$SIGN.ico”, 0)  -This is the line that work in Excel
Dim XLSPadlock As Object
Dim hIcon As Long
hwndIcon = ExtractIconA(0, PathToFile = XLSPadlock.PLEvalVar(“EXEPath”) & “$SIGN.ico” ,0)
Code:
Dim file_name As String


file_name = "$SIGN.ico"

SetExcelIcon ("C:\Program Files\Test\$SIGN.ico")


End Sub
The line that work in Excel

hwndIcon = ExtractIconA(0, ThisWorkbook.Path & “$SIGN.ico”, 0) -This is the line that work in Excel

Here I am inserting the PathToFile This line after PathToFile

hwndIcon = ExtractIconA(0, PathToFile = XLSPadlock.PLEvalVar(“EXEPath”) & “$SIGN.ico” , 0)

Argument not optional

What am I missing please? .Hope someone can help.
 
Last edited:
ThisWorkbook.Path will point to your protected workbook extracted to a hidden temporary virtual drive. Try to put the SIGN.ico into the Add Companion Files to see if it helps. This will extract your ico file to the same virtual folder with the workbook.
 
PhuongM said:
ThisWorkbook.Path will point to your protected workbook extracted to a hidden temporary virtual drive. Try to put the SIGN.ico into the Add Companion Files to see if it helps. This will extract your ico file to the same virtual folder with the workbook.
Thanks PhuongM but the software dont understand THisWorkbook.Path only PathToFile getting argument not optional on PathToFile ?Currently the icon file is in the same directory as the compiled exe which I dont understand…the xlsm file works just not the compiled exe
 
Last edited:
Try Application.ThisWorkbook.Path to see if it works. I guess the ico file must be in the same folder with the workbook, not the exe file.
 
PhuongM said:
Try Application.ThisWorkbook.Path to see if it works. I guess the ico file must be in the same folder with the workbook, not the exe file.
Thank you will try it. My logic tells me keeping the code the same and keeping the structure also the same. The workbook and icon works in the same directory so the Exe and the icon should be the same ???. But I have a problem using that line with PathToFile for some reason PhuongM…now 7days and I cant figure this out (☹️

Is this software compatible with Api 's ??? Hope support can answer this
 
Last edited:
You already got several answers and examples from others; API work in XLS Padlock but in your case, you may have errors in your code.
wndIcon = ExtractIconA(0, ThisWorkbook.Path & “$SIGN.ico”, 0) -This is the line that work in Excel

Here I am inserting the PathToFile This line after PathToFile

hwndIcon = ExtractIconA(0, PathToFile = XLSPadlock.PLEvalVar(“EXEPath”) & “$SIGN.ico” , 0)
Try to replace the last line by:
Code:
Dim PathToFile1 As String

PathToFile1 = XLSPadlock.PLEvalVar("EXEPath") & "$SIGN.ico"

MsgBox (PathToFile1)

hwndIcon = ExtractIconA(0, PathToFile1 ,0)
Then check that the displayed path is correct.
 
gdgsupport said:
You already got several answers and examples from others; API work in XLS Padlock but in your case, you may have errors in your code.
Support may I please remind you the API work FLAWLESSLY in any excel file…the problem is on YOUR SIDE so I dont agree what you telling me that the code are wrong. Its due to INCOMPATIBLITIES on the compile of the exe where it goes highwire and fail AND you are NOT ANSWERING what I have mentioned to you the line throw an error in your compiler

Your VbaCompiler does not understand this line
SendMessageA Application.hWnd, WM_SETICON, ICON_SMALL, hwndIcon


This is 100% an XLSPADLOCK issue and NOT an excell issue and the solution should be provided by your side as in my 7 days struggling to change the icon on your exe it clearly tells me that windows api’s some may not work with XLSPADLOCK.

I have given you the working macro…compile it and see for yourself -so I DONT agree what you trying to blame code…YOUR COMPILER IS THE CULPRIT…if the code was faulty then why does it work in every version of excell but not in your software ?Care to answer that for me please

Golfer65
 
Last edited:
Golfer65 said:
Your VbaCompiler does not understand this line

SendMessageA Application.hWnd, WM_SETICON, ICON_SMALL, hwndIcon

This is 100% an XLSPADLOCK issue and NOT an excell issue and the solution should be provided by your side as in my 7 days struggling to change the icon on your exe it clearly tells me that windows api’s some may not work with XLSPADLOCK.
As we told you here:
5_047764fa20c941da5a8a2a620d7322fb.png
Does Workbook open event work in compiled workbook? XLS Padlock
Put this code in a separate module '--------------------------------------------- Option Explicit Declare Function FindWindow Lib “user32” Alias “FindWindowA” (ByVal ClassName As String, ByVal WindowName As String) As Long Declare Function ExtractIcon Lib “shell32.dll” Alias “ExtractIconA” (ByVal Instance As Long, ByVal ExeFileName As String, ByVal IconIndex As Long) As Long Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal hWnd As Long, ByVal Message As Long, ByVal wPa…
SendMessage isn’t defined in the VBA compiler, so the compiler doesn’t understand this line. Why are you still trying to place your icon code in the VBA compiler, since there is no real secret inside it? Just leave your code in your workbook…

Moreover, if you leave your ChangeExelIcon() in a module as it, it won’t work because there is an error in the code explained above.

Just a last question about this:
to change the icon on your exe
You’re trying to use an icon file to change the window’s icon. Did you define the icon for the EXE file here?
image
 
Support

I am not trying to change the Exe icon…I am trying to change the workbook icon. Example. My app open up with a userform…if I click one button its opening the WORKBOOK window…If I open that that is the icon I want to change the standard excel icon. The icon you refered to above is the Exe icon…not the workbook or form icon

This is my code fully thats 100% functional on ANY office version

Option Explicit
’APIs to format UserForm.
#If VBA7 Then
Declare PtrSafe Function FindWindowA Lib “user32” (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#If Win64 Then
Declare PtrSafe Function GetWindowLongA Lib “user32” Alias “GetWindowLongPtrA” (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
Declare PtrSafe Function SetWindowLongA Lib “user32” Alias “SetWindowLongPtrA” (ByVal HWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#Else
Declare PtrSafe Function GetWindowLongA Lib “user32” (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
Declare PtrSafe Function SetWindowLongA Lib “user32” (ByVal HWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
Declare PtrSafe Function DrawMenuBar Lib “user32” (ByVal HWnd As LongPtr) As Long
Declare PtrSafe Function SetForegroundWindow Lib “user32” (ByVal hwnd As LongPtr) As Long
Declare PtrSafe Function GetForegroundWindow Lib “user32” () As LongPtr
Declare PtrSafe Function ShowWindow Lib “user32” (ByVal HWnd As LongPtr, ByVal nCmdShow As Long) As Long
Declare PtrSafe Function EnableWindow Lib “user32” Alias “EnableWindow” (ByVal hwnd As LongPtr, ByVal fEnable As Long) As Long
Declare PtrSafe Sub Sleep Lib “kernel32” (ByVal dwMilliseconds As Long)
#Else
Declare Function FindWindowA Lib “user32” (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowLongA Lib “user32” (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLongA Lib “user32” (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function DrawMenuBar Lib “user32” (ByVal hWnd As Long) As Long
Declare Function SetForegroundWindow Lib “user32” (ByVal hWnd As Long) As Long
Declare Function GetForegroundWindow Lib “user32” () As Long 'Janela em o foco no WINDOWS
Declare Function ShowWindow Lib “user32” (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Declare Function EnableWindow Lib “user32” (ByVal hWnd As Long, ByVal fEnable As Long) As Long
Declare Sub Sleep Lib “kernel32” (ByVal dwMilliseconds As Long)
#End If

Public Const GWL_HWNDPARENT As Long = -8
Public Const GWL_STYLE = (-16)
Public Const WS_THICKFRAME = &H40000
Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const GWL_EXSTYLE = (-20)
Public Const WS_CAPTION As Long = &HC00000
Public Const WS_EX_APPWINDOW As Long = &H40000 'Show on taskbar

Public Const SW_HIDE = 0
Public Const SW_SHOW = 5
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3

'APIs to set UserForm icon.
#If VBA7 Then
Declare PtrSafe Function ExtractIcon Lib “shell32.dll” Alias “ExtractIconA” (ByVal hInst As LongPtr, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As LongPtr
Declare PtrSafe Function EnumChildWindows Lib “user32” (ByVal hWndParent As LongPtr, ByVal lpEnumFunc As LongPtr, ByVal lParam As LongPtr) As Long
Declare PtrSafe Function GetWindowThreadProcessId Lib “user32” (ByVal HWnd As LongPtr, lpdwProcessId As Long) As Long
Declare PtrSafe Function EnumThreadWindows Lib “user32” (ByVal dwThreadId As Long, ByVal lpfn As LongPtr, ByVal lParam As LongPtr) As Long
Declare PtrSafe Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal HWnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, ByVal lParam As Long) As LongPtr
#Else
Declare Function ExtractIcon Lib “shell32.dll” Alias “ExtractIconA” (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Declare Function EnumChildWindows Lib “user32” (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowThreadProcessId Lib “user32” (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Declare Function EnumThreadWindows Lib “user32” (ByVal dwThreadId As Long, ByVal lpfn As Long, ByVal lParam As Long) As Long
Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
#End If
Public Const GWL_HINSTANCE = (-6)

Sub ChangeExelIcon()

'Get the icon handle.
'You can use the full path of the icon file, i.e.:
'hwndIcon = ExtractIconA(0, “C:\Users\Christos\Desktop\MyApp\Icon.ico”, 0)
'Or the icon path relative to the current workbook, i.e.:
hwndIcon = ExtractIconA(0, ThisWorkbook.Path & “$SIGN.ico”, 0)

'Check if the icon handle is valid.
If hwndIcon <> 0 Then

'Change the icon.
'For a big icon (32 x 32 pixels), use this line:
'SendMessageA Application.HWnd, WM_SETICON, ICON_BIG, hwndIcon
’For a small one (16 x 16 pixels), use the next line (typical case):
SendMessageA Application.hWnd, WM_SETICON, ICON_SMALL, hwndIcon

'Inform the user.
'MsgBox “Excel icon was changed successfully!”, vbInformation, “Done”

End If
End Sub
 
gdgsupport said:
Try to replace the last line by:

Dim PathToFile1 As String

PathToFile1 = XLSPadlock.PLEvalVar(“EXEPath”) & “$SIGN.ico”

MsgBox (PathToFile1)

hwndIcon = ExtractIconA(0, PathToFile1 ,0)

Then check that the displayed path is correct.
Pathtofile errors

Pathtofile2
 
PathToFile is giving me errors

I get argument not optional too on PathToFile

I wish your software understood the BASIC VBA language as 99% of your support is to things your compiler dont understand ThisWorkbook.Path…it doesnt get more elementary than this. Please get your VBA Compiler on Excel standard please

I need a solution to this now please as I waisted 10 days around a simple path and getting software to recognize a simple path
 
Last edited:
Support leave this API as we will NOT SOLVE THIS UNTIL your compiler can understand this line
SendMessageA Application.hWnd, WM_SETICON, ICON_SMALL, hwndIcon

This API work flawlessly in any version of Excell except your software

I need the following thread solved or I will have NO CHOICE to request a refund so please lets leave this API and see if you can get a working VBA macro solved with your PATHTOFILE. This is a MUST SOLVED Macro that MUST be working to prevent a refund
5_f40856482fe1e45ac8f1605885140a2d.png
Read/Import a txt file (MUST WORK FUNCTION SUB) XLS Padlock
Doesnt work Object required I have changed the directory now to c:\Test Public Function PathToFile(filename As String) Dim XLSPadlock As Object On Error GoTo Err Set XLSPadlock = Application.COMAddIns(“GXLSForm.GXLSFormula”).Object PathToFile = XLSPadlock.PLEvalVar(“EXEPath”) & filename Exit Function Err: PathToFile = “C:\Test\Import1.txt” End Function Sub ReadTextFile() Application.ScreenUpdating = False 'Read data from a text file Dim DrawDate As String Dim dDate As Date Dim D…
 
Last edited:
Back
Top