Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Find links with code; change from G drive to C drive

Does anyone know how to find links with code and then
change all of them to always say "G" instead of them being
changed to "C"?

Please be as specific as possible in your reply. I'm a
little rusty on my VBA.

Sandy

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Find links with code; change from G drive to C drive

If your links are only to a handful of workbooks you could just do it
manually using Edit/Links/Change Source.

If you want/need to do it via code then use the following:

Sub EditLinks()

Dim astrLinks()
Dim strLink As String
Dim strNewLink As String

' Retrieve the links as an array
astrLinks = ActiveWorkbook.LinkSources

If Not IsEmpty(astrLinks) Then
For i = 1 To UBound(astrLinks)
strLink = astrLinks(i)

' Only update links starting with 'C'
If Left(strLink, 1) = "C" Then
' Replace the 'C' with 'G'
strNewLink = "G" & Right(strLink, Len(strLink) - 1)
' Update the link
ActiveWorkbook.ChangeLink Name:=strLink _
, NewName:=strNewLink
End If

Next i
End If

End Sub

Regards,
Andrew


"Sandy" wrote in message ...
Does anyone know how to find links with code and then
change all of them to always say "G" instead of them being
changed to "C"?

Please be as specific as possible in your reply. I'm a
little rusty on my VBA.

Sandy

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Find links with code; change from G drive to C drive

Thanks for your reply.

I ran your code, but put in "Dim i As Variant" because it
was screaming about "variable not defined."

It kept popping me into a "File Not Found" Save As dialog
box for each link. Any ideas for a way around that?

Sandy
-----Original Message-----
If your links are only to a handful of workbooks you

could just do it
manually using Edit/Links/Change Source.

If you want/need to do it via code then use the following:

Sub EditLinks()

Dim astrLinks()
Dim strLink As String
Dim strNewLink As String

' Retrieve the links as an array
astrLinks = ActiveWorkbook.LinkSources

If Not IsEmpty(astrLinks) Then
For i = 1 To UBound(astrLinks)
strLink = astrLinks(i)

' Only update links starting with 'C'
If Left(strLink, 1) = "C" Then
' Replace the 'C' with 'G'
strNewLink = "G" & Right(strLink, Len

(strLink) - 1)
' Update the link
ActiveWorkbook.ChangeLink Name:=strLink _
, NewName:=strNewLink
End If

Next i
End If

End Sub

Regards,
Andrew


"Sandy" wrote in message

...
Does anyone know how to find links with code and then
change all of them to always say "G" instead of them

being
changed to "C"?

Please be as specific as possible in your reply. I'm a
little rusty on my VBA.

Sandy

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Find links with code; change from G drive to C drive

Make sure you are changing the link to an existing file.

Regards,
Tom Ogilvy

"Sandy" wrote in message
...
Thanks for your reply.

I ran your code, but put in "Dim i As Variant" because it
was screaming about "variable not defined."

It kept popping me into a "File Not Found" Save As dialog
box for each link. Any ideas for a way around that?

Sandy
-----Original Message-----
If your links are only to a handful of workbooks you

could just do it
manually using Edit/Links/Change Source.

If you want/need to do it via code then use the following:

Sub EditLinks()

Dim astrLinks()
Dim strLink As String
Dim strNewLink As String

' Retrieve the links as an array
astrLinks = ActiveWorkbook.LinkSources

If Not IsEmpty(astrLinks) Then
For i = 1 To UBound(astrLinks)
strLink = astrLinks(i)

' Only update links starting with 'C'
If Left(strLink, 1) = "C" Then
' Replace the 'C' with 'G'
strNewLink = "G" & Right(strLink, Len

(strLink) - 1)
' Update the link
ActiveWorkbook.ChangeLink Name:=strLink _
, NewName:=strNewLink
End If

Next i
End If

End Sub

Regards,
Andrew


"Sandy" wrote in message

...
Does anyone know how to find links with code and then
change all of them to always say "G" instead of them

being
changed to "C"?

Please be as specific as possible in your reply. I'm a
little rusty on my VBA.

Sandy

.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Find links with code; change from G drive to C drive

Thank you very much, Andrew!


-----Original Message-----
If your links are only to a handful of workbooks you

could just do it
manually using Edit/Links/Change Source.

If you want/need to do it via code then use the following:

Sub EditLinks()

Dim astrLinks()
Dim strLink As String
Dim strNewLink As String

' Retrieve the links as an array
astrLinks = ActiveWorkbook.LinkSources

If Not IsEmpty(astrLinks) Then
For i = 1 To UBound(astrLinks)
strLink = astrLinks(i)

' Only update links starting with 'C'
If Left(strLink, 1) = "C" Then
' Replace the 'C' with 'G'
strNewLink = "G" & Right(strLink, Len

(strLink) - 1)
' Update the link
ActiveWorkbook.ChangeLink Name:=strLink _
, NewName:=strNewLink
End If

Next i
End If

End Sub

Regards,
Andrew


"Sandy" wrote in message

...
Does anyone know how to find links with code and then
change all of them to always say "G" instead of them

being
changed to "C"?

Please be as specific as possible in your reply. I'm a
little rusty on my VBA.

Sandy

.

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
when I put my flash drive in, the computer does not give me drive capricorngirlone New Users to Excel 3 April 19th 09 01:51 PM
Links to mapped drive change to refer to local hard drive SueD Links and Linking in Excel 1 May 8th 08 11:42 AM
Obtain drive letter assignment of CD/DVD drive? EagleOne Excel Discussion (Misc queries) 1 October 13th 06 01:27 PM
Can I save to hard drive AND my flash drive at the same time? Gizelle Excel Discussion (Misc queries) 3 July 24th 06 08:27 PM
Link workbooks-C drive to network drive Earl Excel Worksheet Functions 0 April 19th 05 05:50 PM


All times are GMT +1. The time now is 11:20 PM.

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

About Us

"It's about Microsoft Excel"