Been working on formatting an excel file with multiple tabs via access since I not allowed to create as a macro in excel. Did some searching and found a formula for hyperlinking to a cell in another tab based on the value in a cell in the current tab. Trying to convert it such that can be parameterized in access vba. I am putting hyperlinks in col A where the item in column B is colored. Here is the formula. Items in red need to be adjusted via code:
=HYPERLINK(ADDRESS(MATCH(S143,DupesList_304!B:B,0),1,,,"[TARGET_COMPANIES_6125_TL_pd.xlsx]DupesList_304"),"See Companies")
Another part of the problem is dealing with the quotes. I was able to get the row number using [tt]cell.row[/tt] and I can get the index number of the sheet that needs to be used, but can't figure out how to convert the Sheet number to the name. In access vba, ws.name gives me the name of the current sheet, and ws.index+1 can give me the index number of the sheet I want, but not sure how to directly get the name of tab 3. Or do I not need the name in order to populate the above formula? Seems that [tt]worksheets(3).name[/tt] works in Excel but not in access, or the way I set it up, doesn't seem to work. This code should put the hyperlink in the appropriate cell of the current sheet (second tab), but needs to refer to the lookup range using match on the third tab. The hyperlink will take the user to the corresponding cell in the third tab when clicked. Since the tab names change each time the code is run, can't hard code the name.
I started building a string...
[tt]stHyperlink = "S" & cell.row & "," & ws.Index + 1 '& ws.item(3).Name
as well as trying to put into formula...
.cells(cell.row, 1).Formula = "=HYPERLINK(ADDRESS(MATCH(.cells('S'" & .cell.row & ")," & ws.Name & "!B:B,0),1,,,'[" & FileName & "]DupesList_304'),'See Companies')"
[/tt]
Not sure how much of the code is needed to be seen since all the other formatting and looping seems ok. I'll put the beginning part.
=HYPERLINK(ADDRESS(MATCH(S143,DupesList_304!B:B,0),1,,,"[TARGET_COMPANIES_6125_TL_pd.xlsx]DupesList_304"),"See Companies")
Another part of the problem is dealing with the quotes. I was able to get the row number using [tt]cell.row[/tt] and I can get the index number of the sheet that needs to be used, but can't figure out how to convert the Sheet number to the name. In access vba, ws.name gives me the name of the current sheet, and ws.index+1 can give me the index number of the sheet I want, but not sure how to directly get the name of tab 3. Or do I not need the name in order to populate the above formula? Seems that [tt]worksheets(3).name[/tt] works in Excel but not in access, or the way I set it up, doesn't seem to work. This code should put the hyperlink in the appropriate cell of the current sheet (second tab), but needs to refer to the lookup range using match on the third tab. The hyperlink will take the user to the corresponding cell in the third tab when clicked. Since the tab names change each time the code is run, can't hard code the name.
I started building a string...
[tt]stHyperlink = "S" & cell.row & "," & ws.Index + 1 '& ws.item(3).Name
as well as trying to put into formula...
.cells(cell.row, 1).Formula = "=HYPERLINK(ADDRESS(MATCH(.cells('S'" & .cell.row & ")," & ws.Name & "!B:B,0),1,,,'[" & FileName & "]DupesList_304'),'See Companies')"
[/tt]
Not sure how much of the code is needed to be seen since all the other formatting and looping seems ok. I'll put the beginning part.
Code:
Set objapp = CreateObject("Excel.Application")
objapp.Visible = True
Set wb = objapp.workbooks.Open(FileName, True, False)
'select all worksheets & cells In turn
For Each ws In wb.worksheets
'amend font To whatever
With ws
...
...
[indent]If indexcolor = 3 Then
'=HYPERLINK(ADDRESS(MATCH(S143,DupesList_304!B:B,0),1,,,"[TARGET_COMPANIES_6125_TL_pd.xlsx]DupesList_304"),"See Companies")
'stHyperlink = "HYPERLINK(ADDRESS(MATCH(S143,DupesList_304!B:B,0),1,,," '"[TARGET_COMPANIES_6125_TL_pd.xlsx]DupesList_304"'"),"'"See Companies"'")"
stHyperlink = "S" & cell.row & "," & ws.Index + 1 '& ws.item(3).Name
.cells(cell.row, 1).Formula = "=HYPERLINK(ADDRESS(MATCH(.cells('S'" & .cell.row & ")," & ws.Name & "!B:B,0),1,,,'[" & FileName & "]DupesList_304'),'See Companies')"
End If[/indent]