PC Review


Reply
Thread Tools Rate Thread

Change Link in batch of workbooks

 
 
Trish Smith
Guest
Posts: n/a
 
      13th Oct 2008
Hi everyone,

I posted last week and Ron de Bruin pointed me to his website for code that
looped thru files in a folder which was just what I needed.

I've just come back to this bit of work now and realised that the original
code allows you to select the source of the old link and then of the new
link.

I would like to automate this and the old link will be the same for all 40
or so of the wkbks in the folder. The new link will be the active workbook.

ActiveWorkbook.ChangeLink Name:="C:\testing\Source.xls", _
newname:=strnewlink, _
Type:=xlLinkTypeExcelLinks

How do I write it so that newname is the active workbook each time?

Many thanks
--
Trish
 
Reply With Quote
 
 
 
 
Roger Govier
Guest
Posts: n/a
 
      13th Oct 2008
Hi Trish

Maybe
Set strelink = ActiveWorkbook.name

--
Regards
Roger Govier

"Trish Smith" <(E-Mail Removed)> wrote in message
news:E74AF672-C8F5-4720-8841-(E-Mail Removed)...
> Hi everyone,
>
> I posted last week and Ron de Bruin pointed me to his website for code
> that
> looped thru files in a folder which was just what I needed.
>
> I've just come back to this bit of work now and realised that the original
> code allows you to select the source of the old link and then of the new
> link.
>
> I would like to automate this and the old link will be the same for all 40
> or so of the wkbks in the folder. The new link will be the active
> workbook.
>
> ActiveWorkbook.ChangeLink Name:="C:\testing\Source.xls", _
> newname:=strnewlink, _
> Type:=xlLinkTypeExcelLinks
>
> How do I write it so that newname is the active workbook each time?
>
> Many thanks
> --
> Trish


 
Reply With Quote
 
Trish Smith
Guest
Posts: n/a
 
      14th Oct 2008
Hi Roger,

Thanks for the reply.

Does it matter where in the code I place the set statement. Should I put it
in with the change link block or should I put it with all the declarations at
the top?

Thanks again
--
Trish (looking foolish but learning!)


"Roger Govier" wrote:

> Hi Trish
>
> Maybe
> Set strelink = ActiveWorkbook.name
>
> --
> Regards
> Roger Govier
>
> "Trish Smith" <(E-Mail Removed)> wrote in message
> news:E74AF672-C8F5-4720-8841-(E-Mail Removed)...
> > Hi everyone,
> >
> > I posted last week and Ron de Bruin pointed me to his website for code
> > that
> > looped thru files in a folder which was just what I needed.
> >
> > I've just come back to this bit of work now and realised that the original
> > code allows you to select the source of the old link and then of the new
> > link.
> >
> > I would like to automate this and the old link will be the same for all 40
> > or so of the wkbks in the folder. The new link will be the active
> > workbook.
> >
> > ActiveWorkbook.ChangeLink Name:="C:\testing\Source.xls", _
> > newname:=strnewlink, _
> > Type:=xlLinkTypeExcelLinks
> >
> > How do I write it so that newname is the active workbook each time?
> >
> > Many thanks
> > --
> > Trish

>
>

 
Reply With Quote
 
Trish Smith
Guest
Posts: n/a
 
      14th Oct 2008
Hi Roger,

I tried putting the set statement directly after the declarationas and got a
compile error - object required

Any idea what I've doen wrong?
--
Trish


"Roger Govier" wrote:

> Hi Trish
>
> Maybe
> Set strelink = ActiveWorkbook.name
>
> --
> Regards
> Roger Govier
>
> "Trish Smith" <(E-Mail Removed)> wrote in message
> news:E74AF672-C8F5-4720-8841-(E-Mail Removed)...
> > Hi everyone,
> >
> > I posted last week and Ron de Bruin pointed me to his website for code
> > that
> > looped thru files in a folder which was just what I needed.
> >
> > I've just come back to this bit of work now and realised that the original
> > code allows you to select the source of the old link and then of the new
> > link.
> >
> > I would like to automate this and the old link will be the same for all 40
> > or so of the wkbks in the folder. The new link will be the active
> > workbook.
> >
> > ActiveWorkbook.ChangeLink Name:="C:\testing\Source.xls", _
> > newname:=strnewlink, _
> > Type:=xlLinkTypeExcelLinks
> >
> > How do I write it so that newname is the active workbook each time?
> >
> > Many thanks
> > --
> > Trish

>
>

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      14th Oct 2008
Hi Trish

Do you want to remove the links so they point to the cells in the same workbook

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Trish Smith" <(E-Mail Removed)> wrote in message news:E9A3089B-CFB8-48A4-AFE7-(E-Mail Removed)...
> Hi Roger,
>
> I tried putting the set statement directly after the declarationas and got a
> compile error - object required
>
> Any idea what I've doen wrong?
> --
> Trish
>
>
> "Roger Govier" wrote:
>
>> Hi Trish
>>
>> Maybe
>> Set strelink = ActiveWorkbook.name
>>
>> --
>> Regards
>> Roger Govier
>>
>> "Trish Smith" <(E-Mail Removed)> wrote in message
>> news:E74AF672-C8F5-4720-8841-(E-Mail Removed)...
>> > Hi everyone,
>> >
>> > I posted last week and Ron de Bruin pointed me to his website for code
>> > that
>> > looped thru files in a folder which was just what I needed.
>> >
>> > I've just come back to this bit of work now and realised that the original
>> > code allows you to select the source of the old link and then of the new
>> > link.
>> >
>> > I would like to automate this and the old link will be the same for all 40
>> > or so of the wkbks in the folder. The new link will be the active
>> > workbook.
>> >
>> > ActiveWorkbook.ChangeLink Name:="C:\testing\Source.xls", _
>> > newname:=strnewlink, _
>> > Type:=xlLinkTypeExcelLinks
>> >
>> > How do I write it so that newname is the active workbook each time?
>> >
>> > Many thanks
>> > --
>> > Trish

>>
>>

 
Reply With Quote
 
Trish Smith
Guest
Posts: n/a
 
      15th Oct 2008
Hi Ron,

Yes. What I've got are about 40 workbooks each with between 7 and 11 sheets.

I have data coming as single sheet workbboks which I collate using some of
your code. Then to save on time I've got a template with macros to add the
analysis sheets to each of the workbooks. The analysis sheets of the
workbooks have lookup formulas relating back to the original template. So
then the idea is that I change the link source from template to each of the
workbooks so it looks up its own data.

Hope that makes sense :-)

Cheers
--
Trish


"Ron de Bruin" wrote:

> Hi Trish
>
> Do you want to remove the links so they point to the cells in the same workbook
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "Trish Smith" <(E-Mail Removed)> wrote in message news:E9A3089B-CFB8-48A4-AFE7-(E-Mail Removed)...
> > Hi Roger,
> >
> > I tried putting the set statement directly after the declarationas and got a
> > compile error - object required
> >
> > Any idea what I've doen wrong?
> > --
> > Trish
> >
> >
> > "Roger Govier" wrote:
> >
> >> Hi Trish
> >>
> >> Maybe
> >> Set strelink = ActiveWorkbook.name
> >>
> >> --
> >> Regards
> >> Roger Govier
> >>
> >> "Trish Smith" <(E-Mail Removed)> wrote in message
> >> news:E74AF672-C8F5-4720-8841-(E-Mail Removed)...
> >> > Hi everyone,
> >> >
> >> > I posted last week and Ron de Bruin pointed me to his website for code
> >> > that
> >> > looped thru files in a folder which was just what I needed.
> >> >
> >> > I've just come back to this bit of work now and realised that the original
> >> > code allows you to select the source of the old link and then of the new
> >> > link.
> >> >
> >> > I would like to automate this and the old link will be the same for all 40
> >> > or so of the wkbks in the folder. The new link will be the active
> >> > workbook.
> >> >
> >> > ActiveWorkbook.ChangeLink Name:="C:\testing\Source.xls", _
> >> > newname:=strnewlink, _
> >> > Type:=xlLinkTypeExcelLinks
> >> >
> >> > How do I write it so that newname is the active workbook each time?
> >> >
> >> > Many thanks
> >> > --
> >> > Trish
> >>
> >>

>

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      15th Oct 2008
Hi Trish

Untested but this will work i think

mybook.ChangeLink Name:="'C:\testing\Source.xls'", _
newname:=mybook.FullName, _
Type:=xlLinkTypeExcelLinks


Sub Example()
Dim MyPath As String, FilesInPath As String
Dim MyFiles() As String, Fnum As Long
Dim mybook As Workbook
Dim CalcMode As Long
Dim sh As Worksheet
Dim ErrorYes As Boolean

'Fill in the path\folder where the files are
MyPath = "C:\Users\Ron\test"

'Add a slash at the end if the user forget it
If Right(MyPath, 1) <> "\" Then
MyPath = MyPath & "\"
End If

'If there are no Excel files in the folder exit the sub
FilesInPath = Dir(MyPath & "*.xl*")
If FilesInPath = "" Then
MsgBox "No files found"
Exit Sub
End If

'Fill the array(myFiles)with the list of Excel files in the folder
Fnum = 0
Do While FilesInPath <> ""
Fnum = Fnum + 1
ReDim Preserve MyFiles(1 To Fnum)
MyFiles(Fnum) = FilesInPath
FilesInPath = Dir()
Loop

'Change ScreenUpdating, Calculation and EnableEvents
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
End With

'Loop through all files in the array(myFiles)
If Fnum > 0 Then
For Fnum = LBound(MyFiles) To UBound(MyFiles)
Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
On Error GoTo 0

If Not mybook Is Nothing Then


'Change links in mybook
On Error Resume Next

mybook.ChangeLink Name:="'C:\testing\Source.xls'", _
newname:=mybook.FullName, _
Type:=xlLinkTypeExcelLinks


If Err.Number > 0 Then
ErrorYes = True
Err.Clear
'Close mybook without saving
mybook.Close savechanges:=False
Else
'Save and close mybook
mybook.Close savechanges:=True
End If
On Error GoTo 0
Else
'Not possible to open the workbook
ErrorYes = True
End If

Next Fnum
End If

If ErrorYes = True Then
MsgBox "There are problems in one or more files, possible problem:" _
& vbNewLine & "protected workbook/sheet or a sheet/range that not exist"
End If

'Restore ScreenUpdating, Calculation and EnableEvents
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalcMode
End With
End Sub




--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Trish Smith" <(E-Mail Removed)> wrote in message news:33E1328C-81A1-4289-8DC9-(E-Mail Removed)...
> Hi Ron,
>
> Yes. What I've got are about 40 workbooks each with between 7 and 11 sheets.
>
> I have data coming as single sheet workbboks which I collate using some of
> your code. Then to save on time I've got a template with macros to add the
> analysis sheets to each of the workbooks. The analysis sheets of the
> workbooks have lookup formulas relating back to the original template. So
> then the idea is that I change the link source from template to each of the
> workbooks so it looks up its own data.
>
> Hope that makes sense :-)
>
> Cheers
> --
> Trish
>
>
> "Ron de Bruin" wrote:
>
>> Hi Trish
>>
>> Do you want to remove the links so they point to the cells in the same workbook
>>
>> --
>>
>> Regards Ron de Bruin
>> http://www.rondebruin.nl/tips.htm
>>
>>
>> "Trish Smith" <(E-Mail Removed)> wrote in message news:E9A3089B-CFB8-48A4-AFE7-(E-Mail Removed)...
>> > Hi Roger,
>> >
>> > I tried putting the set statement directly after the declarationas and got a
>> > compile error - object required
>> >
>> > Any idea what I've doen wrong?
>> > --
>> > Trish
>> >
>> >
>> > "Roger Govier" wrote:
>> >
>> >> Hi Trish
>> >>
>> >> Maybe
>> >> Set strelink = ActiveWorkbook.name
>> >>
>> >> --
>> >> Regards
>> >> Roger Govier
>> >>
>> >> "Trish Smith" <(E-Mail Removed)> wrote in message
>> >> news:E74AF672-C8F5-4720-8841-(E-Mail Removed)...
>> >> > Hi everyone,
>> >> >
>> >> > I posted last week and Ron de Bruin pointed me to his website for code
>> >> > that
>> >> > looped thru files in a folder which was just what I needed.
>> >> >
>> >> > I've just come back to this bit of work now and realised that the original
>> >> > code allows you to select the source of the old link and then of the new
>> >> > link.
>> >> >
>> >> > I would like to automate this and the old link will be the same for all 40
>> >> > or so of the wkbks in the folder. The new link will be the active
>> >> > workbook.
>> >> >
>> >> > ActiveWorkbook.ChangeLink Name:="C:\testing\Source.xls", _
>> >> > newname:=strnewlink, _
>> >> > Type:=xlLinkTypeExcelLinks
>> >> >
>> >> > How do I write it so that newname is the active workbook each time?
>> >> >
>> >> > Many thanks
>> >> > --
>> >> > Trish
>> >>
>> >>

>>

 
Reply With Quote
 
Trish Smith
Guest
Posts: n/a
 
      15th Oct 2008
Hi Ron,

Thank you so much! :-)

I feel VERY ungrateful asking but, once the code has looped through all
files the error message shows up - I can definitely live with this but it
would be good to see how you would amend code to avoid this.

Thank you once again for code here and on your website
--
Trish (sounding very grovelly :-))


"Ron de Bruin" wrote:

> Hi Trish
>
> Untested but this will work i think
>
> mybook.ChangeLink Name:="'C:\testing\Source.xls'", _
> newname:=mybook.FullName, _
> Type:=xlLinkTypeExcelLinks
>
>
> Sub Example()
> Dim MyPath As String, FilesInPath As String
> Dim MyFiles() As String, Fnum As Long
> Dim mybook As Workbook
> Dim CalcMode As Long
> Dim sh As Worksheet
> Dim ErrorYes As Boolean
>
> 'Fill in the path\folder where the files are
> MyPath = "C:\Users\Ron\test"
>
> 'Add a slash at the end if the user forget it
> If Right(MyPath, 1) <> "\" Then
> MyPath = MyPath & "\"
> End If
>
> 'If there are no Excel files in the folder exit the sub
> FilesInPath = Dir(MyPath & "*.xl*")
> If FilesInPath = "" Then
> MsgBox "No files found"
> Exit Sub
> End If
>
> 'Fill the array(myFiles)with the list of Excel files in the folder
> Fnum = 0
> Do While FilesInPath <> ""
> Fnum = Fnum + 1
> ReDim Preserve MyFiles(1 To Fnum)
> MyFiles(Fnum) = FilesInPath
> FilesInPath = Dir()
> Loop
>
> 'Change ScreenUpdating, Calculation and EnableEvents
> With Application
> CalcMode = .Calculation
> .Calculation = xlCalculationManual
> .ScreenUpdating = False
> .EnableEvents = False
> End With
>
> 'Loop through all files in the array(myFiles)
> If Fnum > 0 Then
> For Fnum = LBound(MyFiles) To UBound(MyFiles)
> Set mybook = Nothing
> On Error Resume Next
> Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
> On Error GoTo 0
>
> If Not mybook Is Nothing Then
>
>
> 'Change links in mybook
> On Error Resume Next
>
> mybook.ChangeLink Name:="'C:\testing\Source.xls'", _
> newname:=mybook.FullName, _
> Type:=xlLinkTypeExcelLinks
>
>
> If Err.Number > 0 Then
> ErrorYes = True
> Err.Clear
> 'Close mybook without saving
> mybook.Close savechanges:=False
> Else
> 'Save and close mybook
> mybook.Close savechanges:=True
> End If
> On Error GoTo 0
> Else
> 'Not possible to open the workbook
> ErrorYes = True
> End If
>
> Next Fnum
> End If
>
> If ErrorYes = True Then
> MsgBox "There are problems in one or more files, possible problem:" _
> & vbNewLine & "protected workbook/sheet or a sheet/range that not exist"
> End If
>
> 'Restore ScreenUpdating, Calculation and EnableEvents
> With Application
> .ScreenUpdating = True
> .EnableEvents = True
> .Calculation = CalcMode
> End With
> End Sub
>
>
>
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "Trish Smith" <(E-Mail Removed)> wrote in message news:33E1328C-81A1-4289-8DC9-(E-Mail Removed)...
> > Hi Ron,
> >
> > Yes. What I've got are about 40 workbooks each with between 7 and 11 sheets.
> >
> > I have data coming as single sheet workbboks which I collate using some of
> > your code. Then to save on time I've got a template with macros to add the
> > analysis sheets to each of the workbooks. The analysis sheets of the
> > workbooks have lookup formulas relating back to the original template. So
> > then the idea is that I change the link source from template to each of the
> > workbooks so it looks up its own data.
> >
> > Hope that makes sense :-)
> >
> > Cheers
> > --
> > Trish
> >
> >
> > "Ron de Bruin" wrote:
> >
> >> Hi Trish
> >>
> >> Do you want to remove the links so they point to the cells in the same workbook
> >>
> >> --
> >>
> >> Regards Ron de Bruin
> >> http://www.rondebruin.nl/tips.htm
> >>
> >>
> >> "Trish Smith" <(E-Mail Removed)> wrote in message news:E9A3089B-CFB8-48A4-AFE7-(E-Mail Removed)...
> >> > Hi Roger,
> >> >
> >> > I tried putting the set statement directly after the declarationas and got a
> >> > compile error - object required
> >> >
> >> > Any idea what I've doen wrong?
> >> > --
> >> > Trish
> >> >
> >> >
> >> > "Roger Govier" wrote:
> >> >
> >> >> Hi Trish
> >> >>
> >> >> Maybe
> >> >> Set strelink = ActiveWorkbook.name
> >> >>
> >> >> --
> >> >> Regards
> >> >> Roger Govier
> >> >>
> >> >> "Trish Smith" <(E-Mail Removed)> wrote in message
> >> >> news:E74AF672-C8F5-4720-8841-(E-Mail Removed)...
> >> >> > Hi everyone,
> >> >> >
> >> >> > I posted last week and Ron de Bruin pointed me to his website for code
> >> >> > that
> >> >> > looped thru files in a folder which was just what I needed.
> >> >> >
> >> >> > I've just come back to this bit of work now and realised that the original
> >> >> > code allows you to select the source of the old link and then of the new
> >> >> > link.
> >> >> >
> >> >> > I would like to automate this and the old link will be the same for all 40
> >> >> > or so of the wkbks in the folder. The new link will be the active
> >> >> > workbook.
> >> >> >
> >> >> > ActiveWorkbook.ChangeLink Name:="C:\testing\Source.xls", _
> >> >> > newname:=strnewlink, _
> >> >> > Type:=xlLinkTypeExcelLinks
> >> >> >
> >> >> > How do I write it so that newname is the active workbook each time?
> >> >> >
> >> >> > Many thanks
> >> >> > --
> >> >> > Trish
> >> >>
> >> >>
> >>

>

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      15th Oct 2008
Hi Trish

Can you tell me what error
Let me know and I will test it for you tomorrow after work.

Bed time for me soon



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Trish Smith" <(E-Mail Removed)> wrote in message news:1A7362F8-E532-4481-B652-(E-Mail Removed)...
> Hi Ron,
>
> Thank you so much! :-)
>
> I feel VERY ungrateful asking but, once the code has looped through all
> files the error message shows up - I can definitely live with this but it
> would be good to see how you would amend code to avoid this.
>
> Thank you once again for code here and on your website
> --
> Trish (sounding very grovelly :-))
>
>
> "Ron de Bruin" wrote:
>
>> Hi Trish
>>
>> Untested but this will work i think
>>
>> mybook.ChangeLink Name:="'C:\testing\Source.xls'", _
>> newname:=mybook.FullName, _
>> Type:=xlLinkTypeExcelLinks
>>
>>
>> Sub Example()
>> Dim MyPath As String, FilesInPath As String
>> Dim MyFiles() As String, Fnum As Long
>> Dim mybook As Workbook
>> Dim CalcMode As Long
>> Dim sh As Worksheet
>> Dim ErrorYes As Boolean
>>
>> 'Fill in the path\folder where the files are
>> MyPath = "C:\Users\Ron\test"
>>
>> 'Add a slash at the end if the user forget it
>> If Right(MyPath, 1) <> "\" Then
>> MyPath = MyPath & "\"
>> End If
>>
>> 'If there are no Excel files in the folder exit the sub
>> FilesInPath = Dir(MyPath & "*.xl*")
>> If FilesInPath = "" Then
>> MsgBox "No files found"
>> Exit Sub
>> End If
>>
>> 'Fill the array(myFiles)with the list of Excel files in the folder
>> Fnum = 0
>> Do While FilesInPath <> ""
>> Fnum = Fnum + 1
>> ReDim Preserve MyFiles(1 To Fnum)
>> MyFiles(Fnum) = FilesInPath
>> FilesInPath = Dir()
>> Loop
>>
>> 'Change ScreenUpdating, Calculation and EnableEvents
>> With Application
>> CalcMode = .Calculation
>> .Calculation = xlCalculationManual
>> .ScreenUpdating = False
>> .EnableEvents = False
>> End With
>>
>> 'Loop through all files in the array(myFiles)
>> If Fnum > 0 Then
>> For Fnum = LBound(MyFiles) To UBound(MyFiles)
>> Set mybook = Nothing
>> On Error Resume Next
>> Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
>> On Error GoTo 0
>>
>> If Not mybook Is Nothing Then
>>
>>
>> 'Change links in mybook
>> On Error Resume Next
>>
>> mybook.ChangeLink Name:="'C:\testing\Source.xls'", _
>> newname:=mybook.FullName, _
>> Type:=xlLinkTypeExcelLinks
>>
>>
>> If Err.Number > 0 Then
>> ErrorYes = True
>> Err.Clear
>> 'Close mybook without saving
>> mybook.Close savechanges:=False
>> Else
>> 'Save and close mybook
>> mybook.Close savechanges:=True
>> End If
>> On Error GoTo 0
>> Else
>> 'Not possible to open the workbook
>> ErrorYes = True
>> End If
>>
>> Next Fnum
>> End If
>>
>> If ErrorYes = True Then
>> MsgBox "There are problems in one or more files, possible problem:" _
>> & vbNewLine & "protected workbook/sheet or a sheet/range that not exist"
>> End If
>>
>> 'Restore ScreenUpdating, Calculation and EnableEvents
>> With Application
>> .ScreenUpdating = True
>> .EnableEvents = True
>> .Calculation = CalcMode
>> End With
>> End Sub
>>
>>
>>
>>
>> --
>>
>> Regards Ron de Bruin
>> http://www.rondebruin.nl/tips.htm
>>
>>
>> "Trish Smith" <(E-Mail Removed)> wrote in message news:33E1328C-81A1-4289-8DC9-(E-Mail Removed)...
>> > Hi Ron,
>> >
>> > Yes. What I've got are about 40 workbooks each with between 7 and 11 sheets.
>> >
>> > I have data coming as single sheet workbboks which I collate using some of
>> > your code. Then to save on time I've got a template with macros to add the
>> > analysis sheets to each of the workbooks. The analysis sheets of the
>> > workbooks have lookup formulas relating back to the original template. So
>> > then the idea is that I change the link source from template to each of the
>> > workbooks so it looks up its own data.
>> >
>> > Hope that makes sense :-)
>> >
>> > Cheers
>> > --
>> > Trish
>> >
>> >
>> > "Ron de Bruin" wrote:
>> >
>> >> Hi Trish
>> >>
>> >> Do you want to remove the links so they point to the cells in the same workbook
>> >>
>> >> --
>> >>
>> >> Regards Ron de Bruin
>> >> http://www.rondebruin.nl/tips.htm
>> >>
>> >>
>> >> "Trish Smith" <(E-Mail Removed)> wrote in message
>> >> news:E9A3089B-CFB8-48A4-AFE7-(E-Mail Removed)...
>> >> > Hi Roger,
>> >> >
>> >> > I tried putting the set statement directly after the declarationas and got a
>> >> > compile error - object required
>> >> >
>> >> > Any idea what I've doen wrong?
>> >> > --
>> >> > Trish
>> >> >
>> >> >
>> >> > "Roger Govier" wrote:
>> >> >
>> >> >> Hi Trish
>> >> >>
>> >> >> Maybe
>> >> >> Set strelink = ActiveWorkbook.name
>> >> >>
>> >> >> --
>> >> >> Regards
>> >> >> Roger Govier
>> >> >>
>> >> >> "Trish Smith" <(E-Mail Removed)> wrote in message
>> >> >> news:E74AF672-C8F5-4720-8841-(E-Mail Removed)...
>> >> >> > Hi everyone,
>> >> >> >
>> >> >> > I posted last week and Ron de Bruin pointed me to his website for code
>> >> >> > that
>> >> >> > looped thru files in a folder which was just what I needed.
>> >> >> >
>> >> >> > I've just come back to this bit of work now and realised that the original
>> >> >> > code allows you to select the source of the old link and then of the new
>> >> >> > link.
>> >> >> >
>> >> >> > I would like to automate this and the old link will be the same for all 40
>> >> >> > or so of the wkbks in the folder. The new link will be the active
>> >> >> > workbook.
>> >> >> >
>> >> >> > ActiveWorkbook.ChangeLink Name:="C:\testing\Source.xls", _
>> >> >> > newname:=strnewlink, _
>> >> >> > Type:=xlLinkTypeExcelLinks
>> >> >> >
>> >> >> > How do I write it so that newname is the active workbook each time?
>> >> >> >
>> >> >> > Many thanks
>> >> >> > --
>> >> >> > Trish
>> >> >>
>> >> >>
>> >>

>>


 
Reply With Quote
 
Trish Smith
Guest
Posts: n/a
 
      15th Oct 2008
Whoops!

Need to put brain in gear before opening mouth!

One of my files had a misnamed tab so obviously needed error message.

Will take another look - sorry Ron! and thank you again
--
Trish


"Ron de Bruin" wrote:

> Hi Trish
>
> Untested but this will work i think
>
> mybook.ChangeLink Name:="'C:\testing\Source.xls'", _
> newname:=mybook.FullName, _
> Type:=xlLinkTypeExcelLinks
>
>
> Sub Example()
> Dim MyPath As String, FilesInPath As String
> Dim MyFiles() As String, Fnum As Long
> Dim mybook As Workbook
> Dim CalcMode As Long
> Dim sh As Worksheet
> Dim ErrorYes As Boolean
>
> 'Fill in the path\folder where the files are
> MyPath = "C:\Users\Ron\test"
>
> 'Add a slash at the end if the user forget it
> If Right(MyPath, 1) <> "\" Then
> MyPath = MyPath & "\"
> End If
>
> 'If there are no Excel files in the folder exit the sub
> FilesInPath = Dir(MyPath & "*.xl*")
> If FilesInPath = "" Then
> MsgBox "No files found"
> Exit Sub
> End If
>
> 'Fill the array(myFiles)with the list of Excel files in the folder
> Fnum = 0
> Do While FilesInPath <> ""
> Fnum = Fnum + 1
> ReDim Preserve MyFiles(1 To Fnum)
> MyFiles(Fnum) = FilesInPath
> FilesInPath = Dir()
> Loop
>
> 'Change ScreenUpdating, Calculation and EnableEvents
> With Application
> CalcMode = .Calculation
> .Calculation = xlCalculationManual
> .ScreenUpdating = False
> .EnableEvents = False
> End With
>
> 'Loop through all files in the array(myFiles)
> If Fnum > 0 Then
> For Fnum = LBound(MyFiles) To UBound(MyFiles)
> Set mybook = Nothing
> On Error Resume Next
> Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum))
> On Error GoTo 0
>
> If Not mybook Is Nothing Then
>
>
> 'Change links in mybook
> On Error Resume Next
>
> mybook.ChangeLink Name:="'C:\testing\Source.xls'", _
> newname:=mybook.FullName, _
> Type:=xlLinkTypeExcelLinks
>
>
> If Err.Number > 0 Then
> ErrorYes = True
> Err.Clear
> 'Close mybook without saving
> mybook.Close savechanges:=False
> Else
> 'Save and close mybook
> mybook.Close savechanges:=True
> End If
> On Error GoTo 0
> Else
> 'Not possible to open the workbook
> ErrorYes = True
> End If
>
> Next Fnum
> End If
>
> If ErrorYes = True Then
> MsgBox "There are problems in one or more files, possible problem:" _
> & vbNewLine & "protected workbook/sheet or a sheet/range that not exist"
> End If
>
> 'Restore ScreenUpdating, Calculation and EnableEvents
> With Application
> .ScreenUpdating = True
> .EnableEvents = True
> .Calculation = CalcMode
> End With
> End Sub
>
>
>
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "Trish Smith" <(E-Mail Removed)> wrote in message news:33E1328C-81A1-4289-8DC9-(E-Mail Removed)...
> > Hi Ron,
> >
> > Yes. What I've got are about 40 workbooks each with between 7 and 11 sheets.
> >
> > I have data coming as single sheet workbboks which I collate using some of
> > your code. Then to save on time I've got a template with macros to add the
> > analysis sheets to each of the workbooks. The analysis sheets of the
> > workbooks have lookup formulas relating back to the original template. So
> > then the idea is that I change the link source from template to each of the
> > workbooks so it looks up its own data.
> >
> > Hope that makes sense :-)
> >
> > Cheers
> > --
> > Trish
> >
> >
> > "Ron de Bruin" wrote:
> >
> >> Hi Trish
> >>
> >> Do you want to remove the links so they point to the cells in the same workbook
> >>
> >> --
> >>
> >> Regards Ron de Bruin
> >> http://www.rondebruin.nl/tips.htm
> >>
> >>
> >> "Trish Smith" <(E-Mail Removed)> wrote in message news:E9A3089B-CFB8-48A4-AFE7-(E-Mail Removed)...
> >> > Hi Roger,
> >> >
> >> > I tried putting the set statement directly after the declarationas and got a
> >> > compile error - object required
> >> >
> >> > Any idea what I've doen wrong?
> >> > --
> >> > Trish
> >> >
> >> >
> >> > "Roger Govier" wrote:
> >> >
> >> >> Hi Trish
> >> >>
> >> >> Maybe
> >> >> Set strelink = ActiveWorkbook.name
> >> >>
> >> >> --
> >> >> Regards
> >> >> Roger Govier
> >> >>
> >> >> "Trish Smith" <(E-Mail Removed)> wrote in message
> >> >> news:E74AF672-C8F5-4720-8841-(E-Mail Removed)...
> >> >> > Hi everyone,
> >> >> >
> >> >> > I posted last week and Ron de Bruin pointed me to his website for code
> >> >> > that
> >> >> > looped thru files in a folder which was just what I needed.
> >> >> >
> >> >> > I've just come back to this bit of work now and realised that the original
> >> >> > code allows you to select the source of the old link and then of the new
> >> >> > link.
> >> >> >
> >> >> > I would like to automate this and the old link will be the same for all 40
> >> >> > or so of the wkbks in the folder. The new link will be the active
> >> >> > workbook.
> >> >> >
> >> >> > ActiveWorkbook.ChangeLink Name:="C:\testing\Source.xls", _
> >> >> > newname:=strnewlink, _
> >> >> > Type:=xlLinkTypeExcelLinks
> >> >> >
> >> >> > How do I write it so that newname is the active workbook each time?
> >> >> >
> >> >> > Many thanks
> >> >> > --
> >> >> > Trish
> >> >>
> >> >>
> >>

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change links for batch of workbooks Trish Smith Microsoft Excel Programming 2 10th Oct 2008 09:53 PM
Need2 batch print all the workbooks in 25 worksheets in one step =?Utf-8?B?cmljaGllIHMu?= Microsoft Excel Misc 2 26th Jun 2006 03:46 PM
How to link cells in two workbooks that change daily? =?Utf-8?B?RG9jIEFkYW1z?= Microsoft Excel Misc 2 14th May 2006 08:47 PM
macro to batch fix errors on password protected workbooks =?Utf-8?B?c3BlbmNl?= Microsoft Excel Programming 4 7th Oct 2005 04:06 AM
How workbooks link to other workbooks =?Utf-8?B?R3JlZw==?= Microsoft Excel Misc 4 11th Aug 2005 07:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:25 AM.