简体   繁体   中英

Excel VBA hyperlink to another workbook and enter values into opened workbook

I am trying to help my Dad put an order and job management 'system' into his manufacturing business.

As part of this I have an 'Orders' workbook with one worksheet containing a table of customer orders where each row is a different order. Each row contains all the key information for each order (order number, qty, product, due date, hyperlink to open related job sheet).

I have written 'job sheets' for all his main and regularly ordered products. These job sheets are contained in separate workbooks.

I would like the user to be able to open the central orders list, click on the link to the job sheet they need to produce the product ordered and then that job sheet be automatically populated with the key order information contained in the target row of the hyperlink clicked.

I have been trying unsuccessfully to write a private sub (using workbook_followHyperlink). I have been trying to use the hyperlinks.address method to capture the name of the workbook being opened and then use that address as the filename to direct where the order information should be entered.

I'm getting better at writing VBA code but I still need a template or 'clue' to begin writing something of my own. I have done MUCH googling to find examples but the only examples I've come across know the name of the destination workbook, or alternatively refer to hyperlinks between sheets within the same workbook .

I would really appreciate even just an outline of what I need to get started.

The Worksheet_FollowHyperlink event fires after Excel has followed the hyperlink (and thus opened the workbook defined in the workbook. It follows that ActiveWorkbook is the workbook defined by the hyperlink. So you could use that. However if you want the actual name form the hyperlink

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim x As Long
Dim s As String
Dim answer As String
For x = Len(Target.Address) To 1 Step -1
     s = Mid(Target.Address, x, 1)
     If s = "\" Then Exit For
     answer = s & answer
Next x
MsgBox answer

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM