Select rows/columns in excel and send them via email

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Select rows/columns in excel and send them via email

Post by Fulminare » 05 Aug 2021, 09:52

I tried searching for this , but could not get it anywhere

(with reference to one of my previous question,)

Code: Select all

xl := ComObjCreate("excel.application")
wrkbk := xl.workbooks.open("C:\Users\Administrater\Desktop\New Microsoft Excel Worksheet.xlsx")


lstrw := xl.Range("A" xl.Rows.Count).End(-4162).Row
mnth := strsplit(xl.Range("B" lstrw).value, "-").2


nwrw := lstrw + 1
nmbr := xl.Range("A" lstrw).value


if nmbr is not number
	nmbr := 0
if (mnth != A_MMM) {
	nmbr := 0
	nwrw++
}






;ENTRIES 

colctxt := "Static Text"
xl.Range("A" nwrw):= nmbr + 1
xl.Range("A" nwrw).NumberFormat := "## "
xl.Range("B" nwrw).value := A_DD "-" A_MM "-" A_YYYY
xl.Range("C" nwrw).value := colctxt
xl.Range("D" nwrw).NumberFormat := "[$-en-US]h:mm Am/Pm;@"
xl.range("D" nwrw).value := A_Hour ":" A_Min ":" A_Sec


wrkbk.close(1)
xl.quit()

Is it possible to select :

1.The rows that have the same month,
2.Columns A to E,

3.Convert the selected columns and rows into pdf ,
4 Send the pdf via email , with the subject " 'month' Data " ?

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

Re: Select rows/columns in excel and send them via email

Post by flyingDman » 05 Aug 2021, 14:55

You are asking for 3 things: select the rows that contain specific data in a certain column, print these rows to a .pdf, email the .pdf. For the last one - emailing as an attachment -, you should be able to find a solution here on the forum. For the first two, here is a solution. Instead of selecting the rows meeting the criteria, I suggest that you hide the ones that do not meet the criteria. You can then print and then unhide the rows.
In the following, the criteria is "cell content in column A is to be equal to 5"; you should be able to adapt it to mnth = XXXX.

Code: Select all

xl := ComObjActive("Excel.Application")
for r in xl.activesheet.usedrange.rows
	if !(xl.range("a" r.row).text = 5) AND (r.row > 1)		;will always include 1 header row
		xl.rows(r.row).EntireRow.Hidden := True
splitpath, % xl.ActiveWorkbook.FullName, , oDir, , oNNE
pth := oDir "\" oNNE ".pdf"
xl.ActiveSheet.ExportAsFixedFormat(0,pth)   				; the file name will be the same as the excel file, except for the extension
xl.activesheet.usedrange.EntireRow.Hidden := False
14.3 & 1.3.7
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Select rows/columns in excel and send them via email

Post by Fulminare » 05 Aug 2021, 22:02

Thank you, I will try this
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Select rows/columns in excel and send them via email

Post by flyingDman » 15 Aug 2021, 12:02

Did you? and...
14.3 & 1.3.7
Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Select rows/columns in excel and send them via email

Post by Fulminare » 15 Aug 2021, 19:44

Oh I am sorry,

Yes it worked.

A PDF file was created

Thank you :)
Post Reply

Return to “Ask for Help (v1)”