Jump to content

Recommended Posts

Posted

As per the title really

I have one cell that needs to have the tab number included inside a formula so if 1st tab is Page 001 the formula for the cell would look like 

=Page 001!A2

 

So as the cell moves to the next tab it would be

 

=Page 002!A2

and so on across 600 pages and its the same cell on every tab

Can someone give me a hint which functions to use please

  • Moderators
Posted

Something like this, you mean?

#include <Excel.au3>

$oExcel = _Excel_Open()
$oWorkBook = _Excel_BookOpen($oExcel, @DesktopDir & "\My.xls")

For $i = 1 To 100
    _Excel_RangeWrite($oWorkBook, $i, "=Page 00" & $i & "!A2", "A1", False)
Next

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted (edited)

I'm using the old excel udf:

#include <Excel.au3>
$oExcel = _ExcelBookOpen(@DesktopDir & "\Book1.xlsx")
$aSheets = _ExcelSheetList($oExcel)
For $i = 1 To UBound($aSheets)-1
    _ExcelSheetActivate($oExcel, $i)
    _ExcelWriteCell($oExcel, $aSheets[$i],"A2")
Next
_ExcelBookSave($oExcel)

That enters fixed text...but if you want to it always pickup the current sheet name:

#include <Excel.au3>
$oExcel = _ExcelBookOpen(@DesktopDir & "\Book1.xlsx")
$aSheets = _ExcelSheetList($oExcel)
For $i = 1 To UBound($aSheets)-1
    _ExcelSheetActivate($oExcel, $i)
;~  _ExcelWriteCell($oExcel, $aSheets[$i],"A2")
    _ExcelWriteFormula($oExcel, '=RIGHT(CELL("filename"),LEN(CELL("filename"))-FIND("]",CELL("filename"),1))', "A2")
Next
_ExcelBookSave($oExcel)
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Posted (edited)

 

Something like this, you mean?

#include <Excel.au3>

$oExcel = _Excel_Open()
$oWorkBook = _Excel_BookOpen($oExcel, @DesktopDir & "\My.xls")

For $i = 1 To 100
    _Excel_RangeWrite($oWorkBook, $i, "=Page 00" & $i & "!A2", "A1", False)
Next

Hmm weird im getting an NAME error with that and it gives me this=Page '0010'!A2

Ideally i would like it to use the tab name and add it in but ill play with it

 

 

I'm using the old excel udf:

#include <Excel.au3>
$oExcel = _ExcelBookOpen(@DesktopDir & "\Book1.xlsx")
$aSheets = _ExcelSheetList($oExcel)
For $i = 1 To UBound($aSheets)-1
    _ExcelSheetActivate($oExcel, $i)
    _ExcelWriteCell($oExcel, $aSheets[$i],"A2")
Next
_ExcelBookSave($oExcel)

That enters fixed text...but if you want to it always pickup the current sheet name:

#include <Excel.au3>
$oExcel = _ExcelBookOpen(@DesktopDir & "\Book1.xlsx")
$aSheets = _ExcelSheetList($oExcel)
For $i = 1 To UBound($aSheets)-1
    _ExcelSheetActivate($oExcel, $i)
;~  _ExcelWriteCell($oExcel, $aSheets[$i],"A2")
    _ExcelWriteFormula($oExcel, '=RIGHT(CELL("filename"),LEN(CELL("filename"))-FIND("]",CELL("filename"),1))', "A2")
Next
_ExcelBookSave($oExcel)

Do these work with the latest excel udf as im on the newest stable?, ill try anyway and see what happens

Nope they dont im trying to work out what the modern equivalent for 

_ExcelSheetActivate($oExcel, $i)

is?

Edited by Chimaera
Posted

Please check the wiki for the Excel page.

Will post details when at home again.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

  • Moderators
Posted

I was writing without testing, as I'm away from a PC. I'm guessing the $bValue parameter, which I set to False for the formula property, is what is causing it. What happens if you set it to True?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

Hmm weird im getting an NAME error with that and it gives me this=Page '0010'!A2

What do you mean by "NAME error"?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

Posted

I was writing without testing, as I'm away from a PC. I'm guessing the $bValue parameter, which I set to False for the formula property, is what is causing it. What happens if you set it to True?

Just the same

What do you mean by "NAME error"?

in the excel cell it shows #NAME? which is an invalid name error i think its caused by the =Page '003'!A2

The easiest way i think would be to just add the tab name into the equation 

"=" & $tabname & !A2

Just a non working example of course, is there an easy way to find the tab name and insert it?

Posted

$oWorkbook.Worksheets($i).Name

gives you the name of the worksheet (tab).




			
		

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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

 

Posted

This works

#include <Excel.au3>

$oExcel = _Excel_Open()

$oWorkBook = _Excel_BookOpen($oExcel, @ScriptDir & "\CS_Catalogue.xlsx")



For $i = 1 To 700
    _Excel_RangeWrite($oWorkBook, $i, "='L:\Cat\CS_Catalogue\[CS_Cat.xlsx]" & $oWorkbook.Worksheets($i).Name & "'!$T$2", "A1", True)
Next

Only slight thing wrong is it doesnt seem to work below tab100 it adds a "0" in front like 049 not sure why but ill have to check the excel sheet to make sure its not from that

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
  • Recently Browsing   0 members

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