Pulling cell value from excel during a loop Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jobro

Pulling cell value from excel during a loop  Topic is solved

15 Aug 2018, 15:11

Hello,
Thanks in advance for looking into this!

I am newer to AHK and am coming up to my first road block. I've tried this a few different ways but haven't gotten it to run smoothly yet. The code worked perfectly before I starting adding in the excel copy function. I think the issue that I am running into is that this is part of a loop. I can't figure out how to insert the ability to copy from excel into the loop without it breaking the loop?

Purpose: Copy the text from cell AY6 in an open excel sheet into a text box in another active program. The text changes everyday thus the need to reference a cell rather than a static piece of text.
Excel Location: "T:/Task Assignments/Order Management/CNF/qsod104 - PFS CNF Overview_180127"
Excel Name: "qsod104 - PFS CNF Overview_180127"
Other Program Name: "Session A - [24 x 80]"

Code: Select all

; This activates the Session A program
{
WinWait, Session A - [24 x 80], 
IfWinNotActive, Session A - [24 x 80], , WinActivate, Session A - [24 x 80], 
WinWaitActive, Session A - [24 x 80], 

; This pastes the nth product number into Session A and opens the text box
; MsgBox % var1 . " | " . var2 . " | loop# " . a_index
sleep, 25
var1 := ArrayOfCols[1][i]									
send, %var1%
sleep, 20

; This pastes the text found in cell AY6 into the Session A text box
???????????
FilePath :=	"T:/Task Assignments/Order Management/CNF/qsod104 - PFS CNF Overview_180127"
oWorkbook := ComObjGet("T:/Task Assignments/Order Management/CNF/qsod104 - PFS CNF Overview_180127") 
MsgBox %	oWorkbook.Sheets(1).Range("AY5").Value 
send, {Ctrl}+V
sleep, 5

; This saves the text in the text box
send, {F7}
sleep, 5

i++
}
Please let me know if I am missing any useful information to help you help me with this.
Thanks!
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Pulling cell value from excel during a loop

15 Aug 2018, 17:29

jobro wrote:Purpose: Copy the text from cell AY6 in an open excel sheet into a text box in another active program. The text changes everyday thus the need to reference a cell rather than a static piece of text.
Excel Location: "T:/Task Assignments/Order Management/CNF/qsod104 - PFS CNF Overview_180127"
Excel Name: "qsod104 - PFS CNF Overview_180127"
Other Program Name: "Session A - [24 x 80]"

Code: Select all

; This pastes the text found in cell AY6 into the Session A text box
???????????
FilePath :=	"T:/Task Assignments/Order Management/CNF/qsod104 - PFS CNF Overview_180127"
oWorkbook := ComObjGet("T:/Task Assignments/Order Management/CNF/qsod104 - PFS CNF Overview_180127") 
MsgBox %	oWorkbook.Sheets(1).Range("AY5").Value 
send, {Ctrl}+V
sleep, 5
You never actually put the information on the clipboard before using control-v to paste.

I would suggest below:

Code: Select all

xlApp := ComObjCreate("Excel.Application")
xlApp.Visible := true		; for testing
xlWorkbook := xlApp.Workbooks.Open(FilePath)
str := xlWorkbook.Sheets(1).Range("AY5").Value
MsgBox %  str	; for testing
Send, % str
; or if you readly need to paste it then uncomment below
; Clipboard := str
; Send, ^v
xlApp.Quit()
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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, jaka1, mikeyww, RussF and 313 guests