Excel question: What cell am I in
Moderators: JRL, Dorian (MJT support)
Excel question: What cell am I in
Does anybody know how to identify what cell is the active cell in Excel?
I am asking this because I have an Excel file that I would like to add to using DDEPoke. I want to avoid having to go to the excel window and identifying the cell myself. It would seem that I should be able to automate the process.
Rory
I am asking this because I have an Excel file that I would like to add to using DDEPoke. I want to avoid having to go to the excel window and identifying the cell myself. It would seem that I should be able to automate the process.
Rory
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Pretty sure you can do that if you use VBscript/COM to automate Excel.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
It may be a little hard to explain. I am generating a spreadsheet from a report of off our Enterprise Management software. The report requires some human intervention as far as decisions. Once I have arrived at the decision, I want to send the data to Excel. Then start the process over for the next item in the list. With having MS stop, I am not sure how to keep the value of the increment for the cell. When I restart the MS script, I need to know which cell to send data to.
I could possibly write the cell increment data to a *.txt file and then read that line to pick it up, but that seems cumbersome.
If it was simply a list to read, it would be easy to use DDEPoke by reading the list on an increment basis and also increment the Cell (R1C1, R1C2, etc...).
Confused?
Rory
I could possibly write the cell increment data to a *.txt file and then read that line to pick it up, but that seems cumbersome.
If it was simply a list to read, it would be easy to use DDEPoke by reading the list on an increment basis and also increment the Cell (R1C1, R1C2, etc...).
Confused?
Rory
A couple of options (at least) that I see here.
1. you are right, you could write to some .txt or INI file the "last used" or "next " values for your cell location....doesn't seem all that cumbersome to me.
OR
2. Just in case some user might alter the spreadsheet, you could have dderequest read through the spreadsheet until it finds the first empty cell or some predetermined marker in the spreadsheet, then start working from that point....I've done this in previous apps and it works very well.
1. you are right, you could write to some .txt or INI file the "last used" or "next " values for your cell location....doesn't seem all that cumbersome to me.
OR
2. Just in case some user might alter the spreadsheet, you could have dderequest read through the spreadsheet until it finds the first empty cell or some predetermined marker in the spreadsheet, then start working from that point....I've done this in previous apps and it works very well.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Like I said. Use VBScript/COM. If you have first opened Excel with VBScript you can later reference any of it's objects. You have access to the properties and methods of the workbooks and sheets just as you would in VBA. Try this example:
Modify the VBRun line to refer to a real excel file. Run the script, wait 10 second and a message box will pop up showing you what cell is currently selected. While waiting 10 seconds you can try changing the selected cell.
Code: Select all
VBSTART
Dim xlApp
Dim xlBook
Sub OpenTheFile(xlFile)
'Create Excel Object (Start Excel)
Set xlApp = CreateObject("Excel.Application")
xlApp.visible = True
'Open the workbook
Set xlBook = xlApp.Workbooks.Open(xlFile)
End Sub
Function GetCurrentCell
GetCurrentCell = xlApp.ActiveCell.Row & "," & xlApp.ActiveCell.Column
End Function
VBEND
VBRun>OpenTheFile,c:\spreadsheets\mybook.xls
Wait>10
VBEval>GetCurrentCell,cname
MessageModal>cname
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?