Creating a hyperlink for a excel sheet: xlsxwriter - python-3.x

Is it possible to create a hyperlink for a specific sheet of an excel file?
I want to open a sheet on the click of a cell which is on another sheet of the same excel file. For example, if someone clicks on 'A1' cell which is in the sheet2 the sheet1 will be opened and both the sheets are in the abc.xlsx file.

You can do this with the XlsxWriter Worksheet write_url() method using the internal: URI. See the XlsxWriter docs on write_url().

I was unable to get this to work using the "write_url(A1, "internal:'sheet name'!A2")" form. Can someone provide some guidance on this?
I was able to successfully add hyperlinks to internal cells using the form:
write('A1', '=HYPERLINK(CELL("address", 'sheet name'!A2), "Friendly Name")
NOTE: the word 'address' is literal/not a generic reference, and, the quotes need to be specified as shown (i.e., single quotes for a multi-word sheet name, and double quotes for the word 'address' and the 'Friendly Name'...

To put a "Friendly Name" in the hyperlink use the string argument of write_url() method. For example, I did the following after setting the variable sheet_name, which in this case is both the name of the sheet to link to and the friendly name:
write_url(row, col, f"internal:'{sheet_name}'!A1", string=sheet_name)

Related

Pull a hyperlink from a hidden sheet Microsoft Excel

I'm trying to pull a hyperlink from a hidden sheet in excel to be used in combination with an IF command, it means there will be 3 arguments.
=IF(A24="","",VLOOKUP(A24,'Product Data '!$A$2:$AD$213,19,FALSE))
Is this possible?
Please see current formula below. How do I add for the hyperlink to be used in conjunction with the IF command as I only want the link to show if specific text is selected.
TIA
In order to use the HYPERLINK from a cell in another cell, you should write it in the HYPERLINK formula:
Something like this:
=HYPERLINK(IF(1=1,VLOOKUP("www.test.com",'Product Data '!A1:A10,1,0)))
The sheet and whether it is hidden or not is irrelevant.

Referring to dynamic worksheets names

is there any way I can use Sheets INDEX instead of NAME to address it?
For example I have
Sheet1 (Calculations)
How can I address this sheet instead of using:
='Calculations'!CELL
I need it as sheets names will be changing according to their values
This link provides a way to do it with a user-defined function in VBA:
referencing sheets by number instead of name in cells
However, you may also want to consider a method that does not change the sheet names. As #DirkReichel implies, you can change sheet indices without changing sheet names and vice versa.
You might try using summary information stored on the sheet in question or keeping a summary sheet that references each sheet.

Why can't Excel update some of the links in my workbook

I have a Master workbook in MS Excel that references data in 4 other workbooks.
When it opens I get the following message:
We can't update some of the links in your workbook right now.
You can continue without updating their values, or edit the links you think are wrong.
[Continue] [Edit Links...]
Each referenced workbook contains a N row, 365 column rectangular range that I have named 'DataRange'
My master workbook contains 4 lots of N row, 365 column ranges with Array Formula linked to these named ranges:
{='C:\Path\[Workbook1Name.xlsx]Sheet'![DataRange]}
It feels like i've come across an Excel bug.. Anyone know what I'm doing wrong?
Are you using MS Excel 2013, when you receive this error?
If so, it maybe due to the "3D reference in your named DataRange" in Excel 2013 or because you're referencing a range or cell in a closed workbook.
Excel allows the defining of names that refer to specific cells or ranges of cells in that workbook, similarly (using the Define Name tool in the Formulas tab) you can assign a formula to a name and then use that name in place of the formula.
The named formula or named data range is part of a collection in that workbook's (workbook1) objects and can be used in different workbook (workbook2), but the link to the defined name in the other workbook must be done one of two ways.
Link the defined name with a formula like this
='C:\Folder\Path\Workbook1.xls'!NamedFormula or NamedDataRange
Or Create a defined name in workbook2 (it can have the same defined name as workbook1's or a new name) and then refer workbook2's defined name to workbook1's defined name. Select Define Name on the Formula tab and copy a link like this in the Refers To Field:
='C:\Folder\Path\Workbook1.xls'!NamedFormula or NamedDataRange
Note these links will only work when being used in simple formulas which treat the link as a direct links. It will not work with more complex formulas when the original workbook (workbook1) is closed because the link is often treated as an indirect link in complicated formulas.
To work around this issue, use either of the following methods:
Save workbook1 and workbook2 as .xlsb files.
Do not add an external reference link to a defined name that refers to a 3D reference or named range.
Or open both workbooks
For more detail information, please refer to the following link:
https://support.microsoft.com/en-us/kb/2755120
If you're still receiving an error/ warning message after trying all my above suggestion. You might want to some troubleshooting.
Try this:
- Open Excel. Under Tools->Options->Calculation, select the Update remote
references box.
Open your workbook. Make sure the box the remote reference box is checked. Save your workbook this way after updating the link. Close workbook and Excel.Restart Excel and open your workbook.
- Look under defined names and delete all that you don't need or that have broken formulae. Run a FindLink search, to pin point the problem.
This process worked for one of workmates with this exact problem.
I hope this helps, if not let me know. There might be a 4th solution.
I finally solved this issue after going on a scavenger hunt. In my case, the reference was to an old file that no longer exists, and removing the reference was all that was needed. Unfortunately Excel does not pinpoint where the reference is, so it was a pain to look for the cell that was making the reference.
In my workbook, it was a reference as a part of a Data Validation. For others seeing the same error, I recommend using the Find & Select -> Go To Special feature (Home ribbon tab) then searching by Formula errors and and Data validation.
Open Excel
Go to "Inquire" tab page in the ribbon
Select "Workbook Analysis"
Check Items\Cells\With Validation Criteria items. In the "Validation Text" you might spot references to the extenal source.
The "Cell Address" column would give you the list of problematic cells.
Look around any other supsicious findings of the Workbook Analysis tool
Have you considered giving the data ranges different names? DataRange1, DataRange2 etc, or is this not possible due to other constraints. When excel says "some" of the links, how far has it got?
I got it working by ditching the FormulaArray and set the FormulaR1C1 for the entire range. Unfortunately the formula was a bit more complicated.
=INDEX(
'C:\Path\Workbook1Name.xlsx'!DataRange,
ROW() - ROW(Workbook1DataRange) + ROW('C:\Path\Workbook1Name.xlsx'!DataRange) - 5,
COLUMN() - COLUMN('C:\Path\Workbook1Name.xlsx'!DataRange) + 1)

How to find the index number of renamed sheets in excel-vba

I have about 8 sheets in a workbook with different names. Is there a way using VBA to activate one ore more of these sheets based on their index number? For example I have sheets named, "Month", "Name", "Age" etc... how can I find their index number?
Try this
Sheets("<sheet Name>").Index
If you want to get code name
Sheets("<sheet Name>").codename
It’s possible for the sheet name to be different from the code name. When you create a sheet, the sheet name and code name are the same, but changing the sheet name doesn’t change the code name, and changing the code name (using the Properties window in the Visual Basic Editor) doesn’t change the sheet name.
To get a sheet's index:
sheets("month").index
To activate by index:
sheets(5).activate

Excel dynamic hyperlink via formula

I am trying to create a hyperlink from one worksheet to another. The worksheet is large and there are many hyperlinks to places all over the other worksheet so I am trying to do this with a formula that I can copy/paste.
Here's what I have:
=HYPERLINK(CELL("address",INDEX('Test Results'!A:A,MATCH("TestCase-001",'Test Results'!A:A,0))),"TestCase-001")
The URI that it evaluates to is: '[Test Results 1.xls]Test Results'!$A$17, and A17 on the Test Results worksheet is indeed the correct cell to link to. The problem is when I click the hyperlink so I can just to test case details, I get an error saying "Cannot open the specified file", and I'm not sure why since the URI looks correct. Any ideas out there to help me fix this?
Using Excel 2003.
The CELL("address",... function returns in the format '[workbook]worksheet'!cell (as you say)
However, HYPERLINK expects [workbook]'worksheet'!cell (note the position of the ' marks) where worksheet name includes spaces.
Simplest answer would be to remove the spaces from the sheet names...
The CELL("address",... function returns in the format '[workbook]worksheet'!cell (as you say)
However, HYPERLINK expects [workbook]'worksheet'!cell (note the position of the ' marks) where worksheet name includes spaces.
Simplest answer would be to remove the spaces from the sheet names...
Figuring out why those two functions wouldn't work together was some great detective work!
Armed with that knowledge, I actually found a way to force the formatting from the response of the CELL function into the format that the HYPERLINK function expects/requires:
=HYPERLINK("[Workbook.xlsx]'Worksheet'!"&CELL("address", A10), "LinkLabel")
Without the full quotes, my version of office (2010) kept truncating the Workbook and Worksheet names because they were referring to the same sheet the code itself was being written in.

Resources