I know how to create Excel object to handle it: oW := ComObjActive("Excel.Application")
I know how to give value to cells on the sheet: oW.ActiveSheet.Cells(1,1).Value := Pole[1]
It took me a lot of time to find just a few simple things like above.
1. Is there some list of all controllable parameters with the right syntax. The syntax for VBA not always work even it is here recommended.
2. Can you write me correct AHK syntax for "Protect workbook structure". (You can find it under File/Info tab) VBA syntax is following: ActiveSheet.Protect "password", "structure", "windows"
3. Can you write me correct AHK syntax for "Encrypt with Password". (You can find it under File/Info tab) VBA syntax is not known for me, sorry.
Thanks a lot.
Sio
How to control Excel with AHK
Re: How to control Excel with AHK
Please help
- Thoughtfu1Tux
- Posts: 125
- Joined: 31 May 2018, 23:26
Re: How to control Excel with AHK
Have you looked at the Excel COM tutorial in the old forum? I used the guide for all of my Excel automation. Read through all the replies to it for even further guides posted by different members of the community.
https://autohotkey.com/board/topic/6903 ... for-excel/
https://autohotkey.com/board/topic/6903 ... for-excel/
Re: How to control Excel with AHK
Yes, I looked and used some of the codes but what I am looking for is a complete list of excel parameters I can automate with correct syntax. This is something I am not able to find anywhere.
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: How to control Excel with AHK
The Microsoft MSDN for Excel contains all the properites, methods, and events of the Excel COM object.
https://docs.microsoft.com/en-us/office ... on(object)
It is a giant branching tree with many layers of properties and methods.
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: How to control Excel with AHK
Thanks a lot, Guru. This is something I had found. The problem I have is then the syntax. Usually, the code is for VB and not working in AHK ... still giving some errors or unknown.
For example this: "Protect workbook structure". (You can find it under File/Info tab) VBA syntax is following: ActiveSheet.Protect "password", "structure", "windows" ... in VBA it works, in AHK at all.
For example this: "Protect workbook structure". (You can find it under File/Info tab) VBA syntax is following: ActiveSheet.Protect "password", "structure", "windows" ... in VBA it works, in AHK at all.
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: How to control Excel with AHK
You just look the "protect" method up in the MSDN:Siopaulo wrote: ↑24 Oct 2018, 02:50Thanks a lot, Guru. This is something I had found. The problem I have is then the syntax. Usually, the code is for VB and not working in AHK ... still giving some errors or unknown.
For example this: "Protect workbook structure". (You can find it under File/Info tab) VBA syntax is following: ActiveSheet.Protect "password", "structure", "windows" ... in VBA it works, in AHK at all.
https://docs.microsoft.com/en-us/office ... et.protect
It shows the syntax as this:
Code: Select all
expression.Protect( _Password_ , _DrawingObjects_ , _Contents_ , _Scenarios_ , _UserInterfaceOnly_ , _AllowFormattingCells_ , _AllowFormattingColumns_ , _AllowFormattingRows_ , _AllowInsertingColumns_ , _AllowInsertingRows_ , _AllowInsertingHyperlinks_ , _AllowDeletingColumns_ , _AllowDeletingRows_ , _AllowSorting_ , _AllowFiltering_ , _AllowUsingPivotTables_ )
expression A variable that represents a Worksheet object.
Code: Select all
xlApp := ComObjActive("Excel.Application")
xlApp.ActiveSheet.Protect("password")
So if you wanted to set _AllowUsingPivotTables_ in AHK you have to put in a bunch of blank parameters: xlApp.ActiveSheet.Protect("password",,,,,,,,,,,,,,,true)
VBA can be useful for examples of how to do things with COM but the MSDN is what is important. VBA and AHK are both accessing the object described in the MSDN.
Edit: I notice now you are mixing the protecting of a workbook and worksheet together. In your example you used ActiveSheet.Protect "password", "structure", "windows". That probably does not work because that is the syntax for a workbook and you used ActiveSheet.
If you want to protect a Workbook this is the link: https://docs.microsoft.com/en-us/office ... ok.protect
And this is the syntax:
Code: Select all
expression.Protect( _Password_ , _Structure_ , _Windows_ )
expression A variable that represents a Workbook object.
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: How to control Excel with AHK
Thank you, trying to more understand. I did following syntax and it does not work. What could be wrong? No errors from AHK. Object oW is created but then nothing will happen.
oW := ComObjActive("Excel.Application")
Sleep, 500
oW.Protect("password",true,true)
oW := ComObjActive("Excel.Application")
Sleep, 500
oW.Protect("password",true,true)
Re: How to control Excel with AHK
FanaticGuru wrote: ↑24 Oct 2018, 12:15Code: Select all
expression A variable that represents a Worksheet object.
Code: Select all
xlApp.ActiveSheet.Protect("password")
Siopaulo, you're trying to use Application.Protect, which does not exist.Siopaulo wrote: ↑25 Oct 2018, 06:17Code: Select all
oW := ComObjActive("Excel.Application") oW.Protect("password",true,true)
Workbook.Protect and Worksheet.Protect on the other hand...
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: How to control Excel with AHK
Like has been stated you are trying to protect the Excel application object when the syntax requires that you protect a workbook object.
Code: Select all
xlApp := ComObjActive("Excel.Application")
xlApp.ActiveWorkbook.Protect("password", ComObject(0xB, -1), ComObject(0xB, -1))
The true and false can sometimes be tricky when working with COM object.
Short Answer:
For true use: ComObject(0xB, -1)
For false use: ComObject(0xB, 0)
Long Answer:
Some COM methods require that you use a COM object true or false. This has to do with data types which in AHK you normally do not have to worry about but many other languages require data to be of a certain stated data type. On the MSDN page it list that it is expecting the two last parameters to be Data Type, Variant and Boolean. 0xB is the code for VT_BOOL data type. In Variant Boolean data types -1 is true and 0 is false.
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Re: How to control Excel with AHK
Thank you so much. Without you, I won´t be able to figure it out. I will test it and make my notes. Anyway as you said something is tricky but I believe I get better in such things through the time.
Who is online
Users browsing this forum: Anput, Marium0505, mcd, mikeyww, Nerafius and 141 guests