Jump to content

Excel - write in file


Recommended Posts

Hello guys,

 

Hopefully somebody can help me in this matter.

I try to write a program that can help me log 2 variables in excel.

I want to use 2 fields to declare tha value for these variables. For example: name and surname.

I want after i write them in background to log them into an excel file: 1 column for name and 1 for surname.

But i don't know how to make it work so that everytime i'm putting a new set of values to put them in a new line so that my excel sheet will start to collect multiple values for my variables.

Hopefully i'm clear enough with what i want to make.

I've searhched big time on google and on forum for simple examples....i can't find any that simple...all of them seems to be so complicated :D and i can't use them to make what i want too.

Obviously i can make it write in specific cells. But i want the Cell number to increase automatically when i have different sets of values.

See example:

$read = _Excel_RangeRead($workbook, $workbook.Activesheet, "A1", 1)
_Excel_RangeWrite($workbook, $workbook.Activesheet, "Test", "A1")

Thank you in advance for any ideas.

Link to comment
Share on other sites

You need to calculate the place where you want to write to. In your case it is the first unused cell. So we first need to calculate the last used cell, get the row number of this cell, add 1 to it and voilá.

$oRange = $oWorkbook.ActiveSheet.UsedRange.SpecialCells($xlCellTypeLastCell) ; Gets the last used cell
$iRow = $oRange.Row ; Row number of the last used cell 
$iRow = $iRow + 1 ; increment by 1 to get the first unused row
$sRange = "A" & $iRow ; Cell where you want to write to

Details can be found in the wiki.
 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...