#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 55
Default Update source in VBA

Im looking for a code that will do the
Edit LinkUpdate source and change the sheet names of the external files to
the correct names in my formulas?


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Update source in VBA

Try using the =HYPERLINK() function

If this post helps click Yes
---------------
Jacob Skaria


"Lost" wrote:

Im looking for a code that will do the
Edit LinkUpdate source and change the sheet names of the external files to
the correct names in my formulas?


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 133
Default Update source in VBA

Do your external files have only one sheet ?
Daniel

Im looking for a code that will do the
Edit LinkUpdate source and change the sheet names of the external files to
the correct names in my formulas?



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 55
Default Update source in VBA

yes i have 7 external files, 6 of them have 6 sheets and the last one has 14.

"Daniel.C" wrote:

Do your external files have only one sheet ?
Daniel

Im looking for a code that will do the
Edit LinkUpdate source and change the sheet names of the external files to
the correct names in my formulas?




  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 133
Default Update source in VBA

Try :

Sub test()
Dim lk, mySheet As String, sh As Worksheet
Dim f As String, p As String, Addr As String
Dim oldTxt As String, newTxt As String, c As Range
Dim Pos As Integer, ResAdr As String
Application.ScreenUpdating = False
For Each lk In ActiveWorkbook.LinkSources(xlExcelLinks)
f = Dir(lk)
Workbooks.Open lk
mySheet = Sheets(1).Name
rep = InputBox("If needed, change the sheet name for workbook "
& f, , mySheet)
If rep < "" Then mySheet = rep

p = ActiveWorkbook.Path
ActiveWorkbook.Close False
oldTxt = "='" & p & "\[" & f & "]"
For Each sh In Sheets
Set c = sh.Cells.Find(oldTxt, , xlFormulas)
If Not c Is Nothing Then
Do
ResAdr = c.Address
Pos = InStr(1, c.Formula, "!")
Adr = Right(c.Formula, Len(c.Formula) - Pos)
newTxt = "='" & p & "\[" & f & "]" & mySheet & "'!"
& Adr
c.Formula = newTxt
Set c = sh.Cells.FindNext(c)
Loop While c < "" And c.Address < ResAdr
End If
Next sh
Next lk
Application.ScreenUpdating = True
End Sub

HTH
Daniel

yes i have 7 external files, 6 of them have 6 sheets and the last one has 14.

"Daniel.C" wrote:

Do your external files have only one sheet ?
Daniel

Im looking for a code that will do the
Edit LinkUpdate source and change the sheet names of the external files to
the correct names in my formulas?








  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 55
Default Update source in VBA

Sorry kinda new to this VB thing -

Where in the VB editor do i put this and do I have to change anything?

"Daniel.C" wrote:

Try :

Sub test()
Dim lk, mySheet As String, sh As Worksheet
Dim f As String, p As String, Addr As String
Dim oldTxt As String, newTxt As String, c As Range
Dim Pos As Integer, ResAdr As String
Application.ScreenUpdating = False
For Each lk In ActiveWorkbook.LinkSources(xlExcelLinks)
f = Dir(lk)
Workbooks.Open lk
mySheet = Sheets(1).Name
rep = InputBox("If needed, change the sheet name for workbook "
& f, , mySheet)
If rep < "" Then mySheet = rep

p = ActiveWorkbook.Path
ActiveWorkbook.Close False
oldTxt = "='" & p & "\[" & f & "]"
For Each sh In Sheets
Set c = sh.Cells.Find(oldTxt, , xlFormulas)
If Not c Is Nothing Then
Do
ResAdr = c.Address
Pos = InStr(1, c.Formula, "!")
Adr = Right(c.Formula, Len(c.Formula) - Pos)
newTxt = "='" & p & "\[" & f & "]" & mySheet & "'!"
& Adr
c.Formula = newTxt
Set c = sh.Cells.FindNext(c)
Loop While c < "" And c.Address < ResAdr
End If
Next sh
Next lk
Application.ScreenUpdating = True
End Sub

HTH
Daniel

yes i have 7 external files, 6 of them have 6 sheets and the last one has 14.

"Daniel.C" wrote:

Do your external files have only one sheet ?
Daniel

Im looking for a code that will do the
Edit LinkUpdate source and change the sheet names of the external files to
the correct names in my formulas?






  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 133
Default Update source in VBA

Sorry kinda new to this VB thing -

Where in the VB editor do i put this and do I have to change anything?


You'll have to put it in a standard module of the workbook you need to
change the links. In the VBE window, right click in the project
correspponding to the workbook, click "Insert" and "module". Then,
paste the code on the right of the window.
Here is a sample file :
http://www.filedropper.com/lost
Daniel


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Source data in a formula akimballsmith Excel Worksheet Functions 2 September 16th 08 07:27 PM
Why will links not update unless source is open? WesJFrank Excel Discussion (Misc queries) 4 August 3rd 07 03:14 PM
Change Source / Update Now buttons not available stickboy Links and Linking in Excel 0 February 16th 06 10:33 PM
Update Chart Source (w/macro?) tx12345 Excel Worksheet Functions 0 January 4th 06 02:18 AM
Update fails. Source not found. Phil Links and Linking in Excel 7 September 12th 05 11:00 PM


All times are GMT +1. The time now is 05:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"