I have 2 Workbooks:
Workbook With Macros
Workbook to write to.
I have 2 subs. One is to insert a hyperlink in the 'workbook to write to' and the other Sub will execute when the hyperlink is clicked.
However, my sub to create the Hyperlink is causing me some confusion. I need to reference the worksheet in the Macro Enabled Workbook, but doing that requires a Workbook.Open command. Obviously the Macro Enabled Workbook will already be open so this closes and re-opens it. I've gotten very muddled with this, can someone point me in the right direction?
So Macro Sheet will have the below Sub, the link is to another Sub in the same sheet. "CreateHyperlinks" is called from another method which writes to an external spreadsheet.
Obviously "ActiveSheet" below is wrong. I want to write to a different spreadsheet, so I will need to open it also (I assume)?
Or, can I pass the worksheet that is being written to from it's write method which is calling "CreateHyperlinks" or am I coupling everything too much as it is?
' This is called elsewhere
Sub CreateHpyerlinks(rangeValue, textValue)
Dim fileName As String
Dim wb As Workbook
Dim TheSheet As Worksheet
fileName = "c:\blah\blah.xlsm"
' ** This is the part: How do i reference "TheSheet" without opening the XL?
Set wb = Workbooks.Open(fileName:=fileName)
Set TheSheet = wb.Sheets("MasterCard")
TheSheet.UsedRange.Select
ActiveSheet.Hyperlinks.Add Anchor:=rangeValue, Address:=TheSheet!THISISMYMACROHERE(textValue), SubAddress:="", ScreenTip:="Go to Word Documebnt", TextToDisplay:=textValue
End Sub
UPDATED:
I have updated the Sub, and am hitting Object does not support his method or property
Sub CreateHpyerlinks(rangeValue, textValue)
Dim fileName As String
Dim wb As Workbook
Dim wbWrite As Workbook
Dim TheSheetWithMacros As Worksheet
Dim TheSheetToWriteTo As Worksheet
fileName = "c:\WorkbookToWriteTo.xlsx"
Set wb = Application.Workbooks(ThisWorkbook.Name)
Set TheSheetWithMacros = wb.Worksheets("Sheet1")
Set wbWrite = Workbooks.Open(fileName:=fileName)
Set TheSheetToWriteTo = wbWrite.Worksheets("Sheet1")
' This Line Errors:
TheSheetToWriteTo.Hyperlinks.Add Anchor:=rangeValue, Address:="", SubAddress:=TheSheetWithMacros!Goto80BytePopulationGuide(textValue), ScreenTip:="Call Macro", TextToDisplay:=textValue
wbWrite.Save
wbWrite.Close
End Sub
The line TheSheetToWriteTo.Hyperlinks.Add Anchor:=rangeValue, Address:="", SubAddress:=TheSheetWithMacros!Goto80BytePopulationGuide(textValue), ScreenTip:="Call Macro", TextToDisplay:=textValue
is at fault, clearly TheSheetWithMacors!CallMacro doesn't work like I had hoped.