Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-25-2020, 12:16 PM
Purfleet Purfleet is offline Importing a file to a sheet with a hyperlink? Windows 10 Importing a file to a sheet with a hyperlink? Office 2019
Expert
 
Join Date: Jun 2020
Location: Essex
Posts: 345
Purfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to behold
Default

A bit basic, but this should do what you want.



The file location needs to be in cell B1 and the file name in B2

Code:
Sub ImportFile()

    Dim fLocation As String
    Dim fName As String
    Dim CurrentfName As String
    
    CurrentfName = ActiveWorkbook.Name
    fLocation = ActiveSheet.Range("B1")
    fName = ActiveSheet.Range("b2")
    
    If Len(Dir(fLocation & fName, vbDirectory)) = 0 Then
        MsgBox Title:="Error", Prompt:="Cant find file"
        Exit Sub
    End If
    
    If Right(fLocation, 1) <> "/" Then
        fLocation = fLocation & "/"
    End If
    
    Workbooks.Open (fLocation & fName)
    
    ActiveSheet.Copy Workbooks(CurrentfName).Sheets(1)
    
    Workbooks(fName).Close False

End Sub
Attached Files
File Type: xlsm Example_Purfleet.xlsm (20.2 KB, 8 views)
Reply With Quote
  #2  
Old 12-26-2020, 10:07 PM
SoMany SoMany is offline Importing a file to a sheet with a hyperlink? Windows 7 64bit Importing a file to a sheet with a hyperlink? Office 2016
Advanced Beginner
Importing a file to a sheet with a hyperlink?
 
Join Date: Oct 2016
Posts: 51
SoMany is on a distinguished road
Default

Quote:
Originally Posted by Purfleet View Post
A bit basic, but this should do what you want.

The file location needs to be in cell B1 and the file name in B2

Code:
Sub ImportFile()

    Dim fLocation As String
    Dim fName As String
    Dim CurrentfName As String
    
    CurrentfName = ActiveWorkbook.Name
    fLocation = ActiveSheet.Range("B1")
    fName = ActiveSheet.Range("b2")
    
    If Len(Dir(fLocation & fName, vbDirectory)) = 0 Then
        MsgBox Title:="Error", Prompt:="Cant find file"
        Exit Sub
    End If
    
    If Right(fLocation, 1) <> "/" Then
        fLocation = fLocation & "/"
    End If
    
    Workbooks.Open (fLocation & fName)
    
    ActiveSheet.Copy Workbooks(CurrentfName).Sheets(1)
    
    Workbooks(fName).Close False

End Sub
I got an error message saying "Cant find file".
Reply With Quote
  #3  
Old 12-26-2020, 11:10 PM
Purfleet Purfleet is offline Importing a file to a sheet with a hyperlink? Windows 10 Importing a file to a sheet with a hyperlink? Office 2019
Expert
 
Join Date: Jun 2020
Location: Essex
Posts: 345
Purfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to behold
Default

Quote:
Originally Posted by Purfleet View Post
A bit basic, but this should do what you want.

The file location needs to be in cell B1 and the file name in B2
Did you put the file location & file name in as per above.......
Reply With Quote
  #4  
Old 12-26-2020, 11:29 PM
SoMany SoMany is offline Importing a file to a sheet with a hyperlink? Windows 7 64bit Importing a file to a sheet with a hyperlink? Office 2016
Advanced Beginner
Importing a file to a sheet with a hyperlink?
 
Join Date: Oct 2016
Posts: 51
SoMany is on a distinguished road
Default

Quote:
Originally Posted by Purfleet View Post
Did you put the file location & file name in as per above.......
Yes. Specifically, I copied the address bar at the top of the folder C:\Users\John Smith\Desktop\1 Work in Progress\Job\Excel\New folder into B1, then typed Sentece.xlsx into B2.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing a file to a sheet with a hyperlink? Hyperlink to open another sheet in same workbook with filtered data tarunbaweja Excel Programming 1 03-20-2016 06:52 AM
Hyperlink Format varies, depending on whether Target file was saved or unsaved on Hyperlink Copy RichardDavey Word 0 05-26-2015 05:26 PM
An error occurred while importing this file <image file> melvinjn Drawing and Graphics 1 01-19-2015 01:32 AM
Importing a file to a sheet with a hyperlink? How to set a hyperlink from a pp presentation into a CELL from an excel sheet Sabi PowerPoint 1 04-30-2013 06:36 AM
Importing a file to a sheet with a hyperlink? Importing a PST file Swoosh983 Outlook 1 08-20-2010 01:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:51 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft