Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Getting Current Link Value

I have a "Core" workbook which several workbooks can use. Right now I have
to physically open the Core workbook and point it to the whichever workbook
it should be looking at now.

How can I determine what is the Core workbook currently linked to using VBA?
The ActiveWorkbook.ChangeLink takes as its first argument the name of the
workbook to which it is currently linked.which I have to replace.

The below is from a recorded macro. My hangup is getting the name of the
existing workbook for that first argument.

ActiveWorkbook.ChangeLink Name:="Jamie11032005XXX.xls", NewName:= _
"PremiumFinancingJamie.xls", Type:=xlExcelLinks
..


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Getting Current Link Value

If you know that you're only linking to one workbook, you could use something
like:

Option Explicit
Sub testme()

Dim aLinks As Variant
Dim iCtr As Long

aLinks = ThisWorkbook.LinkSources

If IsEmpty(aLinks) Then
'no links
Else
MsgBox aLinks(LBound(aLinks))
'or loop through them
'For iCtr = LBound(aLinks) To UBound(aLinks)
' MsgBox aLinks(iCtr)
'Next iCtr
End If

End Sub

(Mostly taken from VBA's help for Linksources.)




Dkline wrote:

I have a "Core" workbook which several workbooks can use. Right now I have
to physically open the Core workbook and point it to the whichever workbook
it should be looking at now.

How can I determine what is the Core workbook currently linked to using VBA?
The ActiveWorkbook.ChangeLink takes as its first argument the name of the
workbook to which it is currently linked.which I have to replace.

The below is from a recorded macro. My hangup is getting the name of the
existing workbook for that first argument.

ActiveWorkbook.ChangeLink Name:="Jamie11032005XXX.xls", NewName:= _
"PremiumFinancingJamie.xls", Type:=xlExcelLinks
.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Getting Current Link Value

It took me a while to get this right but it is working now. I was forgetting
that LinkSources returns an array and that I had to index into the array
even though there was only one value for all the links. I have hundreds of
cells linked between workbooks but they come from only one source.

Thanks for your help.


"Dave Peterson" wrote in message
...
If you know that you're only linking to one workbook, you could use

something
like:

Option Explicit
Sub testme()

Dim aLinks As Variant
Dim iCtr As Long

aLinks = ThisWorkbook.LinkSources

If IsEmpty(aLinks) Then
'no links
Else
MsgBox aLinks(LBound(aLinks))
'or loop through them
'For iCtr = LBound(aLinks) To UBound(aLinks)
' MsgBox aLinks(iCtr)
'Next iCtr
End If

End Sub

(Mostly taken from VBA's help for Linksources.)




Dkline wrote:

I have a "Core" workbook which several workbooks can use. Right now I

have
to physically open the Core workbook and point it to the whichever

workbook
it should be looking at now.

How can I determine what is the Core workbook currently linked to using

VBA?
The ActiveWorkbook.ChangeLink takes as its first argument the name of

the
workbook to which it is currently linked.which I have to replace.

The below is from a recorded macro. My hangup is getting the name of the
existing workbook for that first argument.

ActiveWorkbook.ChangeLink Name:="Jamie11032005XXX.xls", NewName:= _
"PremiumFinancingJamie.xls", Type:=xlExcelLinks
.


--

Dave Peterson



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
link cell in excel to current date Romily Excel Discussion (Misc queries) 3 July 31st 06 01:42 PM
Can I automatically enter the current date or current time into a Ben New Users to Excel 7 October 19th 05 03:38 PM
I want in one worksheet to relatively link to/reference cells in another without changing the format of the current worksheet. [email protected] Excel Discussion (Misc queries) 0 September 22nd 05 04:39 PM
Cells to link to "current workbook" David P. Excel Discussion (Misc queries) 2 June 11th 05 07:38 AM
changing current directory to that of the current open file unnameable Excel Programming 2 May 19th 04 11:14 AM


All times are GMT +1. The time now is 07:45 PM.

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"