I have an autocreating hyperlink (see short code below) but it creates a hyperlink to a file inside the folder where the excel file is. (autosave). But I want it to be linked to the file that is saved manually by the user. (see bigger code below) (right after the auto save). Try pressing on the 'Opslaan' Macro, and you will see what I mean. Anyone has an idea to link to the file where its saved manually? Basically its the same address as in Columns B and C, thats what the address/destination of my hyperlink should be, right now its the folder of the excel file.. Thanks!!
Kopie van Werkorders - Copy.xlsm
Private Sub Worksheet_Change(ByVal Target As Range)
Dim strPath As String, strFile As String
If Target.Count = 1 And Target(1).Column = 1 Then
If Not IsEmpty(Target) Then
strPath = ThisWorkbook.Path & Application.PathSeparator
strFile = Dir$(strPath & Target & ".*")
If Len(strFile) Then
ActiveSheet.Hyperlinks.Add Anchor:=Target.Offset(, 8), _
Address:=strPath & strFile, _
TextToDisplay:=strFile
Else
Target.Offset(, 1).Value = "N/A"
End If
End If
End If
End Sub
Sub MySheetCopy6()
Dim mySourceWB As Workbook
Dim mySourceSheet As Worksheet
Dim myDestWB As Workbook
Dim myNewFileName As String
' First capture current workbook and worksheet
Set mySourceWB = ActiveWorkbook
Set mySourceSheet = ActiveSheet
Dim newnumber As Long 'probably integer would be enough
With mySourceWB.Sheets("overview")
newnumber = .Range("A1").End(xlDown).Value + 1
.Range("A1").End(xlDown).Offset(1, 0).Value = newnumber
End With
Sheets(Sheets.Count).Select
YourValue = Blad1.Range("A65536").End(xlUp).Value
Cells(3, "F").Value = YourValue
ActiveSheet.Name = YourValue
Set YourValue2 = ActiveSheet
' Build new file name based
myNewFileName = mySourceWB.Path & "\" & YourValue2.Name & ".xlsx"
' Add new workbook and save with name of sheet from other file
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=myNewFileName
Set myDestWB = ActiveWorkbook
' Copy over sheet from previous file
mySourceWB.Activate
Sheets(Sheets.Count).Copy After:=myDestWB.Sheets(myDestWB.Worksheets.Count)
' Resave new workbook
ActiveWorkbook.Save
Range("A1").Select
mySourceWB.Activate
Sheets(Sheets.Count).Select
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
Sheets("ORIGINEEL").Copy After:=Worksheets(Worksheets.Count)
Sheets(Sheets.Count).Select
ActiveSheet.Name = "DRAFT"
myDestWB.Activate
Application.Dialogs(xlDialogSaveAs).Show
mySourceWB.Activate
Blad1.Select
Dim rng As Range, onlyname As String
With Workbooks(Workbooks.Count)
onlyname = Left(.Name, InStrRev(.Name, ".") - 1)
Set rng = ActiveWorkbook.ActiveSheet.Columns("A:A").Find(What:=onlyname, _
After:=ActiveWorkbook.ActiveSheet.Cells(1, "A"), LookIn:=xlValues, Lookat _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If rng Is Nothing Then
MsgBox "No name " & .Name & " in Column A"
Else
rng.Offset(0, 1).Value = "='" & .Path & "\[" & .Name & "]" & .Sheets(4).Name & "'!$AB$2"
rng.Offset(0, 2).Value = "='" & .Path & "\[" & .Name & "]" & .Sheets(4).Name & "'!$AC$2"
rng.Offset(0, 3).Value = "='" & .Path & "\[" & .Name & "]" & .Sheets(4).Name & "'!$AD$2"
rng.Offset(0, 4).Value = "='" & .Path & "\[" & .Name & "]" & .Sheets(4).Name & "'!$AE$2"
rng.Offset(0, 5).Value = "='" & .Path & "\[" & .Name & "]" & .Sheets(4).Name & "'!$AF$2"
rng.Offset(0, 6).Value = "='" & .Path & "\[" & .Name & "]" & .Sheets(4).Name & "'!$AG$2"
rng.Offset(0, 7).Value = "='" & .Path & "\[" & .Name & "]" & .Sheets(4).Name & "'!$AH$2"
End If
End With
Range("a" & Cells.Rows.Count).End(xlUp).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWorkbook.Save
End Sub
Bookmarks