PC Review


Reply
Thread Tools Rate Thread

Change links for batch of workbooks

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

I'm hoping someone can help me out.

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

The workbooks originally just held data and new (analysis) sheets were added
from a template.

The analysis sheets have lookup formulas relating back to the original
template.

If it is possible I would be grateful for someone to help me with code that
can go through each of the workbooks (all in the same folder) and change the
link from the template link to the data in the same workbook.

I've found this bit of code in this forum and it does what I want but it's
just as easy to go into the menus and do it that way.

Thanks
Trish

Sub LinksChangeSourcewitherrortrap()

Dim stroldlink As String
Dim strnewlink As String
MsgBox "Select Original link Sourcexxx"

stroldlink = Application.GetOpenFilename _
("Excel files,*.xls")
MsgBox "Select workbook to change"

strnewlink = Application.GetOpenFilename _
("Excel files,*.xls")

MsgBox ActiveWorkbook.Name

On Error GoTo errorLinks 'No colon after label name here
ActiveWorkbook.ChangeLink Name:=stroldlink, _
newname:=strnewlink, _
Type:=xlLinkTypeExcelLinks ' This one works at work

On Error GoTo 0 'Cancels the error call.

Exit Sub 'Place this immediately before errorLinks
'label so does not process unless there is an error.

errorLinks: 'Note the colon after the label name

MsgBox "An error has occurred. " & _
"This is possibly due to one of the following:-" _
& Chr(13) & "Incorrect Workbook name selected and/or" _
& Chr(13) & "Workbooks do not have same Worksheet names." _
& Chr(13) & "Check both the above and then re-run the macro."

End Sub

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

See
http://www.rondebruin.nl/copy4.htm

You can change the red code block to code that make your changes

--

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


"Trish Smith" <(E-Mail Removed)> wrote in message news:06DA35ED-F219-4C73-A8CD-(E-Mail Removed)...
> Hi everyone,
>
> I'm hoping someone can help me out.
>
> I've got about 40 workbooks each with between 7 and 11 sheets.
>
> The workbooks originally just held data and new (analysis) sheets were added
> from a template.
>
> The analysis sheets have lookup formulas relating back to the original
> template.
>
> If it is possible I would be grateful for someone to help me with code that
> can go through each of the workbooks (all in the same folder) and change the
> link from the template link to the data in the same workbook.
>
> I've found this bit of code in this forum and it does what I want but it's
> just as easy to go into the menus and do it that way.
>
> Thanks
> Trish
>
> Sub LinksChangeSourcewitherrortrap()
>
> Dim stroldlink As String
> Dim strnewlink As String
> MsgBox "Select Original link Sourcexxx"
>
> stroldlink = Application.GetOpenFilename _
> ("Excel files,*.xls")
> MsgBox "Select workbook to change"
>
> strnewlink = Application.GetOpenFilename _
> ("Excel files,*.xls")
>
> MsgBox ActiveWorkbook.Name
>
> On Error GoTo errorLinks 'No colon after label name here
> ActiveWorkbook.ChangeLink Name:=stroldlink, _
> newname:=strnewlink, _
> Type:=xlLinkTypeExcelLinks ' This one works at work
>
> On Error GoTo 0 'Cancels the error call.
>
> Exit Sub 'Place this immediately before errorLinks
> 'label so does not process unless there is an error.
>
> errorLinks: 'Note the colon after the label name
>
> MsgBox "An error has occurred. " & _
> "This is possibly due to one of the following:-" _
> & Chr(13) & "Incorrect Workbook name selected and/or" _
> & Chr(13) & "Workbooks do not have same Worksheet names." _
> & Chr(13) & "Check both the above and then re-run the macro."
>
> End Sub
>
> --
> Trish

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

Looks just the job!

Thanks again

--
Trish


"Ron de Bruin" wrote:

> Hi Trish
>
> See
> http://www.rondebruin.nl/copy4.htm
>
> You can change the red code block to code that make your changes
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
> "Trish Smith" <(E-Mail Removed)> wrote in message news:06DA35ED-F219-4C73-A8CD-(E-Mail Removed)...
> > Hi everyone,
> >
> > I'm hoping someone can help me out.
> >
> > I've got about 40 workbooks each with between 7 and 11 sheets.
> >
> > The workbooks originally just held data and new (analysis) sheets were added
> > from a template.
> >
> > The analysis sheets have lookup formulas relating back to the original
> > template.
> >
> > If it is possible I would be grateful for someone to help me with code that
> > can go through each of the workbooks (all in the same folder) and change the
> > link from the template link to the data in the same workbook.
> >
> > I've found this bit of code in this forum and it does what I want but it's
> > just as easy to go into the menus and do it that way.
> >
> > Thanks
> > Trish
> >
> > Sub LinksChangeSourcewitherrortrap()
> >
> > Dim stroldlink As String
> > Dim strnewlink As String
> > MsgBox "Select Original link Sourcexxx"
> >
> > stroldlink = Application.GetOpenFilename _
> > ("Excel files,*.xls")
> > MsgBox "Select workbook to change"
> >
> > strnewlink = Application.GetOpenFilename _
> > ("Excel files,*.xls")
> >
> > MsgBox ActiveWorkbook.Name
> >
> > On Error GoTo errorLinks 'No colon after label name here
> > ActiveWorkbook.ChangeLink Name:=stroldlink, _
> > newname:=strnewlink, _
> > Type:=xlLinkTypeExcelLinks ' This one works at work
> >
> > On Error GoTo 0 'Cancels the error call.
> >
> > Exit Sub 'Place this immediately before errorLinks
> > 'label so does not process unless there is an error.
> >
> > errorLinks: 'Note the colon after the label name
> >
> > MsgBox "An error has occurred. " & _
> > "This is possibly due to one of the following:-" _
> > & Chr(13) & "Incorrect Workbook name selected and/or" _
> > & Chr(13) & "Workbooks do not have same Worksheet names." _
> > & Chr(13) & "Check both the above and then re-run the macro."
> >
> > End Sub
> >
> > --
> > 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
How do I change the links in Excel at one batch? LunaMoon Microsoft Excel Misc 1 24th Apr 2010 12:59 AM
Change Link in batch of workbooks Trish Smith Microsoft Excel Programming 10 15th Oct 2008 09:58 PM
Updating Workbooks from multiple links Workbooks TimJames Microsoft Excel Worksheet Functions 1 15th Dec 2007 03:34 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
macro to batch fix errors on password protected workbooks =?Utf-8?B?c3BlbmNl?= Microsoft Excel Programming 4 7th Oct 2005 04:06 AM


Features
 

Advertising
 

Newsgroups
 


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