Copying files using count to create variables. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Empaque
Posts: 8
Joined: 16 May 2022, 23:28

Copying files using count to create variables.

Post by Empaque » 16 May 2022, 23:52

Hi, im new using AHK to automate some tasks in my worflow.
I followed a guide to store data from an excel sheet, and store it in different variables using the function count.
The problem is that i want to create new files with the names that are stored in the variables
First count is set to 0, then script sets the cursos on column A and copies wathever is there, then makes a loop where if the clipborad is blank the loop breaks, but there is something stored then creates a variable named ''datapoint%count%'' and adds +1 to the count, and starts the loop again untild finds a blank cell.
My problem is that after that i set count=1, and start a new loop to check until wich variable there is no data stored, if ''datapoint%count%'' = blank, the loop breaks, bu if isnt blank, then uses the function Filecopy to copy a selected file like a template ando copies it to a selected path, but when i try to name it with the data stored in the variable, at the moment of using %count% it doesnt name it the way i intend it.
I know the mistake its the way a try to rename the copied file, but i dont find a solution, so i hope somen can help me. :angel:
Here it is the code:

Code: Select all

settitlematchmode, 2

f1::
count=0
Xl := ComObjActive("Excel.Application") ;creates a handle to your currently active excel sheet
Xl.ActiveSheet.Range("a1").select
loop{
send ^c
#HotkeyModifierTimeout, 100
sleep 500
StringReplace, clipboard, clipboard, `r`n,, all
if clipboard = 
 {
 break
 }
Else
 {
 count++
 datapoint%count%=%clipboard%
 send {down}
 }
}
count=1
loop{
if datapoint%count% =  
 {
 break
 }
Else
 {
  FileCopy, C:\Users\tigre\Desktop\Pruebas\ZAPATAS.xlsx, C:\Users\tigre\Desktop\Pruebas\Prueba\%datapoint%count%%.xlsx,
 count++
 }
}
return


Sorry for the bad grammar, english its no my first lenguage. :angel:

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Copying files using count to create variables.

Post by BoBo » 17 May 2022, 00:02

Sorry for the bad grammar, english its no my first lenguage.
Why not checking out the free browser extension from Grammarly(.com)? ;)

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Copying files using count to create variables.  Topic is solved

Post by flyingDman » 17 May 2022, 01:59

So,if I understand correctly, you want to create excel files based on a template called zapatos.xlsx. The names of these files will be the content of the cells in column A in the currently open excel spreadsheet. If there are empty cells in column A, these cells will be skipped. If this is correct, the following should accomplish that:

Code: Select all

SetWorkingDir := a_scriptdir              ; or whatever path
Xl := ComObjActive("Excel.Application")
for c in xl.activesheet.usedrange.columns(1).cells
	if c.text
		FileCopy, zapatos.xlsx, % c.text ".xlsx"
14.3 & 1.3.7

Empaque
Posts: 8
Joined: 16 May 2022, 23:28

Re: Copying files using count to create variables.

Post by Empaque » 17 May 2022, 23:14

flyingDman wrote:
17 May 2022, 01:59
So,if I understand correctly, you want to create excel files based on a template called zapatos.xlsx. The names of these files will be the content of the cells in column A in the currently open excel spreadsheet. If there are empty cells in column A, these cells will be skipped. If this is correct, the following should accomplish that:

Code: Select all

SetWorkingDir := a_scriptdir              ; or whatever path
Xl := ComObjActive("Excel.Application")
for c in xl.activesheet.usedrange.columns(1).cells
	if c.text
		FileCopy, zapatos.xlsx, % c.text ".xlsx"
So awesome!!!, That worked perfectly and it was way easier than waht i had before, thanks a lot :D .

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Copying files using count to create variables.

Post by flyingDman » 18 May 2022, 00:36

:thumbup:
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”