Results 1 to 1 of 1

Hyperlink macro linking other file

Threaded View

IKZOUHETNIETWETEN Hyperlink macro linking other... 03-04-2014, 05:40 PM
  1. #1
    Forum Contributor
    Join Date
    08-01-2012
    Location
    rotterdam, holland
    MS-Off Ver
    Excel 2013
    Posts
    170

    Hyperlink macro linking other file

    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
    Last edited by IKZOUHETNIETWETEN; 03-04-2014 at 05:47 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Linking a macro to a hyperlink....
    By tvanover in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2013, 08:49 PM
  2. Macro to Hyperlink - Different file name
    By akrothian in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-22-2012, 02:38 PM
  3. Macro Hyperlink Code to File - Need Help
    By ineedsomehelp89 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-28-2011, 03:49 PM
  4. Replies: 1
    Last Post: 01-26-2006, 01:00 AM
  5. [SOLVED] Macro to Copy Hyperlink to another file as a HYPERLINK, not text...
    By dollardoc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-06-2005, 08:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1