Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-22-2012, 08:16 AM
OssOss OssOss is offline linking in excel Windows 7 64bit linking in excel Office 2010 64bit
Novice
linking in excel
 
Join Date: Jul 2012
Posts: 4
OssOss is on a distinguished road
Default linking in excel

Hya for all i have a bit fifficult question thus its possible to create a dinamically changing link in excel i mean i have a buch of excel files and i need to extract exact data from them to an another excel file and im too lazy to create a separate long command lines for all of them i wanna to make an one command line and dinamically replace the file name in that command which ones are indicated in the adjacent columm in the output sheet.


all files are named lkie this :1.slxs, 2.xlsx.... up to thousands...

i thinking about a solutions something like this:
='C:\Users\Oss\Downloads\[(number of the file).xlsx]Sheet1'!$A$1

is there possible to do a stuff like that?

who solve it for me i owe him a beer :-)
Reply With Quote
  #2  
Old 07-22-2012, 09:18 AM
Catalin.B Catalin.B is offline linking in excel Windows Vista linking in excel Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, România
Posts: 386
Catalin.B is on a distinguished road
Default

Your problem is very similar to this one: https://www.msofficeforums.com/excel...ta-source.html
The code can be changed to take the data from all excel files in a folder...
But , obviously or not, this is not the only way.
Reply With Quote
  #3  
Old 07-22-2012, 09:35 AM
OssOss OssOss is offline linking in excel Windows 7 64bit linking in excel Office 2010 64bit
Novice
linking in excel
 
Join Date: Jul 2012
Posts: 4
OssOss is on a distinguished road
Default Umm

Well its loooks like i kinda still a bit of lost how to get it done :-((shame on me) fo example i wanted to use a wariable from cell C1 as a "filename"
Reply With Quote
  #4  
Old 07-22-2012, 09:42 AM
Catalin.B Catalin.B is offline linking in excel Windows Vista linking in excel Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, România
Posts: 386
Catalin.B is on a distinguished road
Default

Upload a file with a list of source files names, and specify the range of cells you need from these files, i will give you a sample code...
Reply With Quote
  #5  
Old 07-22-2012, 09:55 AM
OssOss OssOss is offline linking in excel Windows 7 64bit linking in excel Office 2010 64bit
Novice
linking in excel
 
Join Date: Jul 2012
Posts: 4
OssOss is on a distinguished road
Default incoming

Well im sending those fils well i must say o owe you a big time thank you in advance
Attached Files
File Type: xlsx Test.xlsx (8.2 KB, 11 views)
Reply With Quote
  #6  
Old 07-22-2012, 10:48 AM
Catalin.B Catalin.B is offline linking in excel Windows Vista linking in excel Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, România
Posts: 386
Catalin.B is on a distinguished road
Default

This is the code you will find in the file attached. Just press the start button , in the browse window that comes up, navigate to the folder that contains your source files and double click any file from that folder; the code opens every file from that folder and copies cells A58 to column D.
Code:
Option Explicit
Sub ChangeLinks()
Application.ScreenUpdating = False
Dim NewLnk As String
 
NewLnk = Application.GetOpenFilename("Excel files,*.xl*", _
                           1, "Choose any file in the source folder", , False)
                           
       If TypeName(NewLnk) = "Boolean" Then Exit Sub
       
    Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")

Dim Fisier, FolderSursa As String, LastRow As Long
LastRow = ThisWorkbook.Sheets("1000000").Range("D" & Rows.Count).End(xlUp).Row
  FolderSursa = oFSO.GetFile(NewLnk).ParentFolder
         For Each Fisier In oFSO.GetFolder(FolderSursa).Files
            Workbooks.Open (Fisier)
            ActiveSheet.Cells(58, "A").Copy
            ThisWorkbook.Activate
            ThisWorkbook.Sheets("1000000").Cells(LastRow + 1, "D").Select
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
            Workbooks(Fisier.Name).Close savechanges:=False
            LastRow = LastRow + 1
         Next
         
 
End Sub
Attached Files
File Type: xlsm Test-v1.xlsm (20.6 KB, 9 views)
Reply With Quote
  #7  
Old 07-22-2012, 11:22 AM
OssOss OssOss is offline linking in excel Windows 7 64bit linking in excel Office 2010 64bit
Novice
linking in excel
 
Join Date: Jul 2012
Posts: 4
OssOss is on a distinguished road
Default

Hey than you a lot
Reply With Quote
  #8  
Old 07-22-2012, 11:29 AM
Catalin.B Catalin.B is offline linking in excel Windows Vista linking in excel Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, România
Posts: 386
Catalin.B is on a distinguished road
Default

You're wellcome
Reply With Quote
  #9  
Old 07-23-2012, 10:46 PM
Catalin.B Catalin.B is offline linking in excel Windows Vista linking in excel Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, România
Posts: 386
Catalin.B is on a distinguished road
Default

Well, i took the time to make another solution to your problem, with another approach, which is much faster than the previous , because it extracts the data from the target files without opening and closing those files. This version uses the list of workbooks in column A and a defined name with an Excel 4 macro formula (GET.CELL) to extract the file name from the existing link. Of course, this can be done completely in the code.
You might need to manually change the link from cell B3 to a real file in your computer, the code will not run with a broken link (actual link is to a file in my computer)
Code:
Option Explicit
Sub ChangeLinks()
Application.ScreenUpdating = False
Dim OldLnk, NewLnk, Target, i As String, j As Integer
 
NewLnk = Application.GetOpenFilename("Excel files,*.xl*", _
                           1, "Choose any file in the source folder", , False)
                           
       If TypeName(NewLnk) = "Boolean" Then Exit Sub
       
    Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")

Dim Fisier, FolderSursa As String, LastRow As Long
LastRow = ThisWorkbook.Sheets("1000000").Range("D" & Rows.Count).End(xlUp).Row
  FolderSursa = oFSO.GetFile(NewLnk).ParentFolder
        For j = 3 To Sheets("1000000").Range("A" & Rows.Count).End(xlUp).Row
                 For Each Fisier In oFSO.GetFolder(FolderSursa).Files
                      Target = Sheets("1000000").Cells(j, "A")
                          If InStr(1, Fisier.Name, Target, vbTextCompare) > 0 Then
                              i = Fisier.Name
                              OldLnk = Sheets("1000000").Cells(3, "C").Text
                              ActiveWorkbook.ChangeLink Name:=OldLnk, _
                              NewName:=i, Type:=xlExcelLinks
                              Sheets("1000000").Cells(3, "B").Copy
                              Sheets("1000000").Cells(LastRow + 1, "D").Select
                              Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                              :=False, Transpose:=False
                              LastRow = LastRow + 1
                           End If
                 Next
         Next j
 Application.CutCopyMode = False
End Sub
If you do not want to use a defined name to extract tha path to source file, and you want the code to do all the work, you have to use this code:
Code:
Option Explicit
Sub ChangeLinks()
Application.ScreenUpdating = False
Dim OldLnk, NewLnk, Target, i As String, j As Integer
 
NewLnk = Application.GetOpenFilename("Excel files,*.xl*", _
                           1, "Choose any file in the source folder", , False)
                           
       If TypeName(NewLnk) = "Boolean" Then Exit Sub
       
    Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")

Dim Fisier, FolderSursa As String, LastRow As Long
With ThisWorkbook.Sheets("1000000")
LastRow = .Range("D" & Rows.Count).End(xlUp).Row
  FolderSursa = oFSO.GetFile(NewLnk).ParentFolder
        For j = 3 To .Range("A" & Rows.Count).End(xlUp).Row
                 For Each Fisier In oFSO.GetFolder(FolderSursa).Files
                      Target = .Cells(j, "A")
                          If InStr(1, Fisier.Name, Target, vbTextCompare) > 0 Then
                              i = Fisier.Name
                              
                            With Application ' extracting path with VB from existing link in cell B3 (without using defined name in worksheet)
                               OldLnk = .Substitute(.Cells(3, "B").Formula, "=", "")
                               OldLnk = Left(OldLnk, .Find("]", OldLnk) - 1)
                               OldLnk = .Substitute(OldLnk, "[", "")
                            End With
                              
                              
                              ActiveWorkbook.ChangeLink Name:=OldLnk, _
                              NewName:=i, Type:=xlExcelLinks
                              .Cells(3, "B").Copy
                              .Cells(LastRow + 1, "D").Select
                              Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                              :=False, Transpose:=False
                              LastRow = LastRow + 1
                           End If
                 Next
         Next j
 Application.CutCopyMode = False
 End With
End Sub
Attached Files
File Type: xlsm Test-v2.xlsm (21.7 KB, 8 views)
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
linking in excel linking to excel from word jillapass Word VBA 5 06-08-2012 01:28 AM
linking in excel linking word from Excel Lorna B Word 1 03-22-2012 03:36 PM
Excel to powerpoint linking mugezhn Excel 0 07-08-2010 02:56 AM
Linking Excel to Word engineer_in_training Word 0 01-06-2010 01:30 PM
Linking from Excel to Word streng Word 4 10-28-2008 08:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:24 PM.


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