Link to home
Start Free TrialLog in
Avatar of Sharafudheen K A
Sharafudheen K A

asked on

How to Add Hyperlink to cell for link another sheet cell

I am new to python, Now am trying to update a cell with hyperlink which refer to another cell sheet. i have tryed with below code but while click the cell its showing error with "Cannot open the specified file". Could you any one can help on this ?

from win32com.client import Dispatch
excel = Dispatch('Excel.Application')
book = excel.Workbooks.Open("Location.xls")
sheet = book.Worksheets(1)
cell_location = sheet.Cells(2,2)
cell_destination = book.Worksheets(2).Cells(1,3)
sheet.Hyperlinks.Add(Anchor=cell_location, Address=cell_destination)
book.Save()
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sharafudheen K A
Sharafudheen K A

ASKER

Thnaks for your command

cell_destination = '#' + Sheet_name + '!$C$30'   # if it for C30 cell from sheet_name
sheet.Hyperlinks.Add(Anchor=cell_location, Address=cell_destination)

by updating this my issue was resolved.
Solution according to author's comment