[solved]How to transform VBA code to AHK?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zhanglei1371
Posts: 28
Joined: 05 Aug 2014, 02:01

[solved]How to transform VBA code to AHK?

20 Dec 2017, 10:00

this is a vba code for convert digit value to Str.

Code: Select all

Selection.TextToColumns Destination:=Selection.Cells(1), DataType:=1, TextQualifier:=1, FieldInfo:=Array(1, 2)
but if i want to transform it to ahk,how to do ?
Thx.
Last edited by zhanglei1371 on 21 Dec 2017, 03:38, edited 1 time in total.
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: How to transform VBA code to AHK?

20 Dec 2017, 11:22

Do you need to? From the help file:
"Variable types: AutoHotkey has no explicitly defined variable types. However, a variable containing only digits (with an optional decimal point) is automatically interpreted as a number when a math operation or comparison requires it. (To improve performance, numbers are cached internally to avoid conversions to/from strings.)"
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: How to transform VBA code to AHK?

20 Dec 2017, 14:04

zhanglei1371 wrote:this is a vba code for convert digit value to Str.

Code: Select all

Selection.TextToColumns Destination:=Selection.Cells(1), DataType:=1, TextQualifier:=1, FieldInfo:=Array(1, 2)
but if i want to transform it to ahk,how to do ?
Thx.
AHK does not allow named parameters so you have to put the parameters in the correct slot.

Here is an untested start:

Code: Select all

xlApp := ComObjActive("Excel.Application")
xlApp.Selection.TextToColumns(xlApp.Selection.Cells(1), 1, 1,,,,,,,,Array(1,2))
Also Excel assumes you want to work with the Excel application. With AHK you have to explicitely state that when you call methods.

Below is a link showing the order of all the parameters. The first three are easy but the FieldInfo is the 11th slot so got to put blank parameters to get to the 11th slot for FieldInfo. This parameter is expecting an array so you have to understand what Excel is expecting here to get this parameter right.
https://msdn.microsoft.com/en-us/vba/ex ... thod-excel

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
zhanglei1371
Posts: 28
Joined: 05 Aug 2014, 02:01

How to transform VBA code to AHK?

21 Dec 2017, 03:37

Here is an untested start:

Code: Select all

xlApp := ComObjActive("Excel.Application")
xlApp.Selection.TextToColumns(xlApp.Selection.Cells(1), 1, 1,,,,,,,,Array(1,2))
Also Excel assumes you want to work with the Excel application. With AHK you have to explicitely state that when you call methods.

FG[/quote]
Thx very much.
I had found the reason for my puzzle.
The origin is in VBA。The Macro I record was in wrong slot。So when I adjust the position of the variable,The code work。

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: emp00, hiahkforum, mstrauss2021, ntepa and 112 guests